0

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.

  • Did you install and set up whitenoise, as recommended in the Heroku documentation? – Flimm Jul 13 '17 at 17:16
  • Yes, I did. I updated my post, too. –  Jul 13 '17 at 17:22
  • You used the `collectstatic` command? Are all static files copied? – hansTheFranz Jul 13 '17 at 17:37
  • When I run `python3 manage.py collectstatic`I get `No such file or directory: '/Users/myUser/Projects/DockerProject/Project/backend/project/project/static'` –  Jul 13 '17 at 17:44
  • I have created directory `static` manually. Everything works fine both locally and on Heroku. Thanks for your support. I will update my post. –  Jul 13 '17 at 17:50
  • @Wahtdbogh was this comment for me? I didn't do anything. Or did my collectstatic hint made you find the mistake? – hansTheFranz Jul 13 '17 at 19:21
  • 1
    It was a comment to you and Flimm. I just wanted to thank you for your willingness to help. –  Jul 13 '17 at 19:25

0 Answers0