Django Heroku 引发 ValueError ("Missing staticfiles manifest entry for ' %s'"% clean_name)

标签 django heroku

我收到 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 staticheroku 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/

相关文章:

javascript - Angular 6 : Npm ERR! 缺少脚本:部署到 heroku 时启动

python - Virtualenv 和 Pip 永远挂起

带 Docker、Nginx、Gunicorn 和 SSL 的 Django

python - 为 Django 中两个不同类的选项创建外键

heroku - 在 Heroku 上将 hobby-dev 升级为 hobby-basic

python - Heroku 的 Gunicorn 和 Bottle 设置

Django - 将我的模型链接到配置文件(UserProfile)模型

django - 当下游处理 ssl 时,Nginx 在同一 server_name block 上从 http 重写为 https

ruby-on-rails - 无效的配置选项 `:provider'

ssl - 如何使用 rails 5 和 devise 4 在 heroku 上设置安全连接