Django and Static Assets
Last updated February 22, 2023
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.
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
$ 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.
Sometimes, you may not want Heroku to run collectstatic on your behalf. You can disable the collectstatic build step with the
$ heroku config:set DISABLE_COLLECTSTATIC=1
This will fully disable the collectstatic step of the build.