I've followed the official Heroku docs on Django and Static Assets; I've installed dj-static
and added it to my requirements.txt
file, properly configured all the variables in my settings.py
file:
STATIC_ROOT = os.path.join(CONFIG_ROOT, 'served/static/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(CONFIG_ROOT, 'static'),
)
And this is what my wsgi.py
looks like:
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_django_project.settings")
from django.core.wsgi import get_wsgi_application
from dj_static import Cling
application = Cling(get_wsgi_application())
The contents of Procfile
:
web: gunicorn --bind 0.0.0.0:$PORT my_django_project.wsgi:application
In the docs, it says that "collectstatic is run automatically when it is configured properly." But when I navigate to my site there's clearly no css.
I've tried debugging using heroku run
, but that just copies the static files as expected.
I've noticed that when I include the collectstatic
command in my Procfile
, i.e.
web: python my_django_project/manage.py collectstatic --noinput ; gunicorn -b 0.0.0.0:$PORT my_django_project.wsgi:application
...that works as expected, and the static files are served.
However what's strange about that is when I run heroku run bash
and look inside the directory that STATIC_ROOT
is pointing to, there's nothing there! In fact, the entire served/
directory is missing, and yet, the static files are still being served!
I'd still like to know why isn't collectstatic
being run automatically though -- like mentioned in the docs -- when I deploy my Django app to Heroku.