试图了解“上传文件”的工作方式我发现views.py没有获取相对于STATIC_ROOT和STATIC_URL在settings.py中指定的值。但views.py获取STATICFILES_DIRS的值,此值不正确。
settings.py
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, ""),]
urls.py
urlpatterns = [url(r'get_object/$', views.get_object, name = 'get_object'),]
views.py
def get_object(self):
# static_files = settings.STATICFILES_DIRS
static_root = settings.STATIC_ROOT
if static_root:
path = static_root
else:
path ='No object'
return HttpResponse(path)
Django返回'No object'。当我输入 views.py static_files而不是static_root
时def get_object(self):
static_files = settings.STATICFILES_DIRS
# static_root = settings.STATIC_ROOT
if static_files:
path = static_files
else:
path ='No object'
return HttpResponse(path)
它返回'C:/ music /'。我想这不是正确的道路。它提供了相对于BASE_DIR的正确路径。我希望得到正确的STATIC_ROOT。提前谢谢!