我试图通过ManifestStaticFilesStorage
在我的Wagtail网站上启动并运行静态文件版本控制/缓存。当我上传到我的舞台服务器时,我得到Internal Server Error
。知道可能会发生什么吗?
我的base.py是我的基本设置,stage.py是我的舞台设置。回溯也包含在下面。
base.py
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
STATICFILES_DIRS = [
os.path.join(PROJECT_DIR, 'assets'),
]
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
stage.py
DEBUG = False
STATIC_ROOT = '/data/web/stage.sitename.com/web/static/'
STATIC_URL = '/static/'
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
回溯:
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/core/handlers/exception.py” in get_exception_response
98. response = callback(request, **dict(param_dict, exception=exception))
File “/data/virtualenv/sitename/lib/python2.7/site-packages/newrelic-2.70.0.51/newrelic/hooks/framework_django.py” in wrapper
503. return wrapped(*args, **kwargs)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/utils/decorators.py” in _wrapped_view
149. response = view_func(request, *args, **kwargs)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/views/defaults.py” in page_not_found
45. body = template.render(context, request)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/backends/django.py” in render
66. return self.template.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render
208. return self._render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/newrelic-2.70.0.51/newrelic/api/function_trace.py” in dynamic_wrapper
98. return wrapped(*args, **kwargs)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in _render
199. return self.nodelist.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render
994. bit = node.render_annotated(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render_annotated
961. return self.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/loader_tags.py” in render
174. return compiled_parent._render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/newrelic-2.70.0.51/newrelic/api/function_trace.py” in dynamic_wrapper
98. return wrapped(*args, **kwargs)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in _render
199. return self.nodelist.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render
994. bit = node.render_annotated(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render_annotated
961. return self.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/loader_tags.py” in render
210. return template.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render
210. return self._render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/newrelic-2.70.0.51/newrelic/api/function_trace.py” in dynamic_wrapper
98. return wrapped(*args, **kwargs)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in _render
199. return self.nodelist.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render
994. bit = node.render_annotated(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/template/base.py” in render_annotated
961. return self.render(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/templatetags/static.py” in render
104. url = self.url(context)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/templatetags/static.py” in url
101. return self.handle_simple(path)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/templatetags/static.py” in handle_simple
114. return staticfiles_storage.url(path)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py” in url
132. hashed_name = self.stored_name(clean_name)
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py” in stored_name
292. cache_name = self.clean_name(self.hashed_name(name))
File “/data/virtualenv/sitename/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py” in hashed_name
95. (clean_name, self))
Exception Type: ValueError at /favicon.ico Exception Value: The file ‘build/img/favicon.ico’ could not be found with <django.contrib.staticfiles.storage.ManifestStaticFilesStorage object at 0x7fee94178190>. Request information: USER: AnonymousUser
答案 0 :(得分:2)
错误是由于设置
STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.ManifestStaticFilesStorage'
如果将其用于生产,则必须确保我们在项目中使用的每个静态资产均可用。如果我们错过任何资产,则会收到错误Missing staticfiles manifest entry
。
要解决该错误,请在运行以下命令后首先在DEBUG=False
中设置settings.py
。
python manage.py collectstatic --clear --noinput
执行上述命令后,它将显示清单错误。尝试修复错误,然后再次运行命令。重复相同的操作,直到成功运行而不会引发错误。
答案 1 :(得分:0)
在渲染页面之前,你有没有做过python manage.py collectstatic?