Reputation: 3327
I have deployed by Django project as a Heroku app, but can not get the static files to work.
settings.py
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
STATIC_URL = 'static/'
# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'static'),
)
which is exactly what is recommended at Django and Static Assets
I have set DISABLE_COLLECTSTATIC to false with,
$ heroku config:set DISABLE_COLLECTSTATIC=0 --app mathsproject
The file system looks like this,
which shows that the 'static' directory is in the root of my Django project. But I do not see where the 'staticfiles' directory is? Should this be created somewhere?
When running,
$ heroku logs
I typically get errors showing that the static files are missing. And this is obvious in the browser too.
......
2016-07-11T07:39:30.187273+00:00 app[web.1]: Not Found: /static/assets/js/jquery-1.10.2.min.js
2016-07-11T07:39:30.264037+00:00 app[web.1]: Not Found: /static/assets/img/4.png
2016-07-11T07:39:30.283627+00:00 app[web.1]: Not Found: /static/assets/img/testimonials/1.jpg
........
Whitenoise has been enabled by adding, to mathProject/wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mathsProject.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
To the bottom of settings.py I put
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
Running
$ heroku run bash
and then,
$ python manange.py collectstatic --noinput
this gives several lines of errors, the last of which is,
OSError: [Errno 2] No such file or directory: '/app/mathsProject/static'
But there is a 'static' directory in 'mathsProject'
Thanks,
Upvotes: 2
Views: 1736
Reputation: 3327
The static files are recognised when the 'static' directory is inside the Django project directory, which unfortunately had the same name as the whole Django directory. Both were called 'mathsProject'.
Also I set,
$ heroku config:set DISABLE_COLLECTSTATIC=1
This works for me.
Upvotes: 1