Django and Static Assets
Last updated November 29, 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, Django’s collectstatic command (python manage.py collectstatic
) is run automatically during the build. A build will fail if the collectstatic step is not successful.
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.