I have a problem with static files using Django with Docker on Heroku. When I open app I get errors like this on Heroku:
2017-07-13T13:37:43.271635+00:00 heroku[router]: at=info method=GET path="/static/rest_framework/js/default.js" host=myapp.herokuapp.com request_id=3bfd8d31-193e-48e8-bb6e-aee9f353ffee fwd="109.173.154.199" dyno=web.1 connect=1ms service=15ms status=404 bytes=291 protocol=https
and like this locally:
django_1 | [13/Jul/2017 13:35:01] "GET /static/rest_framework/js/default.js HTTP/1.1" 404 109
I tried to do it on the basis of many answers, for instance this topic, unfortunately nothing works. Any suggestions?
My settings.py
based on Heroku documentation:
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'
I added whitenoise
to requirements.txt
.
wsgi.py:
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
SOLUTION
I couldn't run python3 manage.py collectstatic
because of No such file or directory static in my project tree
. Then python3 manage.py collectstatic
solved my problem.