我收到 500 服务器错误,因为我的静态文件似乎有问题:
我的项目文件夹名称是 register 并且我有不同的生产和开发设置文件:
register
--live-static
--register
----settings
------__init__.py
-----common.py
-----production.py
-----development.py
--live-static
--static
在我的 production.py
我有文件:from register.settings.common import *
import django_heroku
django_heroku.settings(locals())
DEBUG = False
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'live-static', 'static-root')
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'live-static', 'media-root'
我已经跑了:python manage.py collect static
heroku run python manage.py collectstatic
我得到了以下结果:1626 static files copied to '/app/live-static/static-root', 4464 post-processed.
但是,在访问我的网站后,出现错误:raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
2020-09-07T19:46:28.324481+00:00 app[web.1]: ValueError: Missing staticfiles manifest entry for 'css/main.css'
在我的模板中,我有 {% static 'css/main.css' %}
我不知道为什么我仍然收到错误,因为我的收集静态已经正常工作。我很感激任何帮助。
最佳答案
来自 Whitenoise docs看来你的 main.css
可能有对其他文件的引用:
The most common issue is that there are CSS files which reference other files (usually images or fonts) which don’t exist at that specified path. When Django attempts to rewrite these references it looks for the corresponding file and throws an error if it can’t find it.
我建议您更改 STATICFILES_STORAGE 的值,看看它是否有效:
+ STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
- STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
关于Django Heroku 引发 ValueError ("Missing staticfiles manifest entry for ' %s'"% clean_name),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63783517/