在 Heroku 上找不到 Django 静态文件(带有白噪声) [英] Django staticfiles not found on Heroku (with whitenoise)

查看:21
本文介绍了在 Heroku 上找不到 Django 静态文件(带有白噪声)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题似乎被问了好几次,但我无法解决.

This question seems to be asked several time but I can not fix it.

我使用 DEBUG = False 在生产环境中部署了一个 django 应用程序.我设置了我的 allowed_host.我使用 {% load static from staticfiles %} 来加载静态文件.我完全写下了 Heroku doc 建议的设置:

I deployed a django app on production with DEBUG = False. I set my allowed_host. I used {% load static from staticfiles %} to load static files. I exactly write the settings sugested by Heroku doc :

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'),
)

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

但是我得到了一个错误 500.并且得到了这个回溯(通过邮件)

BUT I got an error 500. And got this traceback (by mail)

...
`cache_name = self.clean_name(self.hashed_name(name))
 File "/app/.heroku/python/lib/python3.5/site-    packages/django/contrib/staticfiles/storage.py", line 94, in hashed_name (clean_name, self))
...
ValueError: The file ‘app/css/font.css’ could not be found with <whitenoise.django.GzipManifestStaticFilesStorage object at 0x7febf600a7f0>.`

当我运行 heroku run python manage.py collectstatic --noinput一切看起来都不错:

When I run heroku run python manage.py collectstatic --noinput All seems ok :

276 个静态文件复制到/app/annuaire/staticfiles",276 个后处理.

有没有人有想法可以帮助我吗?

Does anyone have an idea to help me, please ?

谢谢

annuaire
|-- /annuaire
|-- -- /settings.py
|-- /app
|-- -- /static/...`

wsgi.py

from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise


application = get_wsgi_application()
application = DjangoWhiteNoise(application)

推荐答案

我明白了.我需要添加

python manage.py collectstatic --noinput;

在我的 Procfile 中.Heroku 文档说 collecticstatic 是自动触发的.https://devcenter.heroku.com/articles/django-assets

in my Procfile. Heroku doc said that collecticstatic is automatically triggered. https://devcenter.heroku.com/articles/django-assets

谢谢

这篇关于在 Heroku 上找不到 Django 静态文件(带有白噪声)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆