这个问题似乎已经被问过多次,但我无法解决它。
我在生产环境中部署了一个 Django 应用程序,DEBUG=False
。我设置了我的 allowed_host
。我使用 {% load static from staticfiles %}
加载静态文件。我完全按照 Heroku 文档建议的设置编写了代码:
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个静态文件被复制到'/app/annuaire/staticfiles',276个被处理。
有没有人能帮我想个主意,谢谢?
谢谢
编辑:
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)
STATIC_ROOT
来确保它与 '/app/annuaire/staticfiles'
相同? - agcontiFileNotFoundError:[Errno 2] No such file or directory:'/app/annuaire/static'
。 - vpoulain/
页面无法正常工作,而/admin
页面可以正常渲染。此外,我已经检查过了,我的静态文件可以被 Web 服务器返回:http://localhost:8000/static/app/style.css
能够返回状态码为 HTTP 200。在我的控制台里显示"GET / HTTP/1.1" 500 27
。 - vpoulain