没有在Heroku找到Django静态文件(with whitenoise) [英] Django staticfiles not found on Heroku (with whitenoise)
问题描述
我使用 DEBUG = False
在部署了一个django应用程序。我设置了我的 allowed_host
。
我使用 {%static 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))
文件 /app/.heroku/python/lib/python3.5/site- packages / django / contrib / staticfiles / storage.py,第94行,hashed_name(clean_name,self))
...
ValueError:使用< whitenoise.django.GzipManifestStaticFilesStorage对象(0x7febf600a7f0>)找不到文件'app / css / font.css'。
当我运行 heroku运行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)
我知道了我需要添加
python manage.py collectstatic --noinput;
在我的Procfile。 Heroku doc表示, collecticstatic
被自动触发。
https://devcenter.heroku.com/articles/django-assets
谢谢
This question seems to be asked several time but I can not fix it.
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'
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>.`
When I run heroku run python manage.py collectstatic --noinput
All seems ok :
276 static files copied to '/app/annuaire/staticfiles', 276 post-processed.
Does anyone have an idea to help me, please ?
Thanks
EDIT :
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)
I got it. I needed to add
python manage.py collectstatic --noinput;
in my Procfile. Heroku doc said that collecticstatic
is automatically triggered.
https://devcenter.heroku.com/articles/django-assets
Thanks
这篇关于没有在Heroku找到Django静态文件(with whitenoise)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!