【发布时间】:2016-06-01 03:13:42
【问题描述】:
这个问题似乎被问了好几次,但我无法解决。
我使用DEBUG = False 在生产环境中部署了一个 django 应用程序。我设置了我的allowed_host。
我使用{% load static from staticfiles %} 加载静态文件。我完全编写了 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。并得到了这个回溯(通过邮件)
...
`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
一切似乎都很好:
276 static files copied to '/app/annuaire/staticfiles', 276 post-processed.
有没有人可以帮帮我?
谢谢
编辑:
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)
【问题讨论】:
-
Django 通常只在 DEBUG=False 时调用该特定函数,所以我很困惑你会在 DEBUG=True 时得到该错误。我建议使用 DEBUG=False 在本地测试您的应用程序,运行
collectstatic,然后运行runserver,看看您是否收到该错误。会不会是你还没有提交那个特定的文件? -
对不起!当 Debug 为 False 时,你是对的!
-
您是否打印了
STATIC_ROOT以确保它与'/app/annuaire/staticfiles'相同? -
我刚做了(本地)我得到了
In [3]: settings.STATIC_ROOT Out[3]: '/Users/vincentpoulain/xxxx/annuaire/annuaire/staticfiles':/ -
我尝试改成
STATIC_ROOT = os.path.join(BASE_DIR, '../app/staticfiles')
标签: python django heroku django-staticfiles