所以我从来没有部署过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.
我的模板呈现只是找到但我似乎无法弄清楚为什么没有找到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" />
感谢你的帮助,因为我很难过。
答案 0 :(得分:1)
<强>更新强>
原来是缺少上下文处理器。要在模板中获取STATIC_URL设置,您必须注册staticfiles
上下文处理器:
TEMPLATE_CONTEXT_PROCESSORS = [
...
'django.core.context_processors.static',
...
]
首先刺伤:
看起来您需要将该dir添加到静态源列表中(重新:上面的注释):
# list of input paths for collectstatic
STATICFILES_DIRS = [
os.path.join(PROJECT_ROOT, "tulsa", "static"),
# you'll want to remove this path:
#os.path.join(PROJECT_ROOT, "site_media", "static"),
]
# output path for collectstatic
STATIC_ROOT = os.path.join(PROJECT_ROOT, "site_media", "static")