Configuring Django Apps for Heroku
Last updated February 22, 2023
The basics
First, and most importantly, Heroku web applications require a Procfile
.
This file is used to explicitly declare your application’s process types and entry points. It is located in the root of your repository.
Procfile
web: gunicorn myproject.wsgi
This Procfile requires Gunicorn, the production web server that we recommend for Django applications. For more information, see Deploying Python Applications with Gunicorn.
Installing gunicorn
$ pip install gunicorn
Be sure to add gunicorn
to your requirements.txt
file as well.
settings.py
changes
On Heroku, sensitive credentials are stored in the environment as config vars. This includes database connection information (named DATABASE_URL
), which is traditionally hardcoded in Django applications.
As such, you will need to configure your app’s settings.py
file to read these environment variables into Django settings.
For examples of this, see the example settings.py
in the Getting Started with Python project on GitHub.
Lastly, see Django and Static Assets for how to configure Django for static assets in production.