Django and Static Assets
Last updated May 30, 2024
Table of Contents
WhiteNoise
Django does not support serving static files in production. However, the fantastic WhiteNoise project can integrate into your Django application, and was designed with exactly this purpose in mind.
See the WhiteNoise Django documentation for more details.
There is also a full example settings.py
in the Getting Started with Python project on GitHub.
Collectstatic during builds
When a Django application is deployed to Heroku, $ python manage.py collectstatic --noinput
is run automatically during the build. A build will fail if the collectstatic step is not successful.
Debugging
If collectstatic failed during a build, a traceback was provided that will be helpful in diagnosing the problem. If you need additional information about the environment collectstatic was run in, use the DEBUG_COLLECTSTATIC
configuration.
$ heroku config:set DEBUG_COLLECTSTATIC=1
This will display in your build output all of the environment variables that were available to Python when the collectstatic command was executed.
Disabling Collectstatic
Sometimes, you may not want Heroku to run collectstatic on your behalf. You can disable the collectstatic build step with the DISABLE_COLLECTSTATIC
configuration:
$ heroku config:set DISABLE_COLLECTSTATIC=1
This will fully disable the collectstatic step of the build.