【发布时间】:2012-10-15 02:50:39
【问题描述】:
所以我从来没有部署过 Django 应用程序,我正在努力加快速度。我运行了 collectstatic 命令,现在我的静态文件都不会呈现。当我运行 findstatic 命令时,我收到一条异常消息:
django.core.exceptions.ImproperlyConfigured: The storage backend of the staticfiles finder <class 'django.contrib.staticfiles.finders.DefaultStorageFinder'> doesn't have a valid location.
我的模板呈现只是 find 但我似乎无法弄清楚为什么找不到 css 文件。从我的设置模块中突出显示:
settings/
base.py
devel.py
prod.py
base.py
cwd = os.path.dirname(os.path.abspath(__file__))
PROJECT_ROOT = cwd[:-9] # chop off "settings/"
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
]
TEMPLATE_LOADERS = [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
]
TEMPLATE_DIRS = [
os.path.join(PROJECT_ROOT, "templates"),
]
devl.py
STATIC_URL = "/site_media/static/"
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "site_media", "static"),
]
STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")
site_base.html
<link rel="stylesheet" href="{{ STATIC_URL }}css/site_base.css" />
非常感谢您的帮助,因为我很难过。
【问题讨论】:
-
有STATIC_ROOT 设置?
-
是的。 static_root 设置已更新并包含在上面。
-
更重要的是,有了那个查找器,你有DEFAULT_FILE_STORAGE 设置吗?
-
看起来默认是
django.core.files.storage.FileSystemStorage。加载程序查找storage.base_location,FileSystemStorage上的默认值为MEDIA_ROOT。您可以尝试将MEDIA_ROOT指向您的静态文件。 -
这可能都是一个红鲱鱼,虽然我认为
FileSystemFinder和AppDirectoriesFinder应该找到你的静态文件,即使第三个失败。顺便问一下,从您的 PROJECT_ROOT 到您的site_base.css的路径是什么?
标签: django django-settings django-staticfiles django-static