【问题标题】:Django Heroku raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)Django Heroku raise ValueError("Missing staticfiles manifest entry for '%s'" % clean_name)
【发布时间】:2020-09-07 19:55:33
【问题描述】:

我收到 500 服务器错误,因为我的静态文件似乎有问题:

我的项目文件夹名称是注册,我有不同的生产和开发设置文件:

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' %}

我不知道为什么我仍然收到错误,因为我的 collect static 已经正常工作。 如有任何帮助,我将不胜感激。

【问题讨论】:

    标签: django heroku


    【解决方案1】:

    从Whitenoise docs 看来,您的main.css 可能引用了其他文件:

    最常见的问题是,有一些 CSS 文件引用了该指定路径中不存在的其他文件(通常是图像或字体)。当 Django 尝试重写这些引用时,它会查找相应的文件,如果找不到则抛出错误。

    我建议你更改 STATICFILES_STORAGE 的值,看看是否有效:

    + STATICFILES_STORAGE = 'whitenoise.storage.CompressedStaticFilesStorage'
    - STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
    

    【讨论】:

      【解决方案2】:

      对我来说,这些设置有效:

      # STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # try disabling it
      WHITENOISE_USE_FINDERS = True
      WHITENOISE_MANIFEST_STRICT = False
      WHITENOISE_ALLOW_ALL_ORIGINS = True
      

      【讨论】:

      • 这是唯一对我有用的东西,谢谢!
      猜你喜欢
      • 2018-11-12
      • 2018-03-10
      • 2019-03-21
      • 1970-01-01
      • 1970-01-01
      • 2021-09-12
      • 2012-03-13
      • 1970-01-01
      • 2022-07-28
      相关资源
      最近更新 更多