This article will describe how to deploy a Django app to Heroku, which includes the necessary setup in Heroku’s dashboard.
A PlanetScale database — If you haven't created a database, refer to our PlanetScale quickstart guide to get started.
A Heroku account.
A project deployed to Heroku — If you're just poking around and don't already have an application to deploy, you can use our Django sample.
There are a few requirements for running a Django application in Heroku:
django-herokupackages as requirements.
A properly setup Procfile.
Proper Config Var setup in Heroku.
This article will make use of the django-example GitHub repository that is built for the Connect a Django application to PlanetScale document
It’s important to store the connection details for the PlanetScale database in Config Vars in Heroku so they are properly secured. These details can be obtained from the PlanetScale dashboard by clicking the "Connect" button.
In the following modal, choose Django from the “Connect with” dropdown. The .env tab will show all of the Config vars that need to be set up in Heroku. Take note of these and head to the Heroku dashboard.
Select the Settings tab of your Heroku project and then “Reveal Config Vars” from the Config Vars section. You should see your current Config Vars or an empty set of inputs if there are none configured yet.
Set up a separate Config Var for each line you captured from the PlanetScale dashboard. The one exception is the
MYSQL_ATTR_SSL_CA, which should be set to
Heroku uses Ubuntu by default to run applications deployed to their systems, which is why the
MYSQL_ATTR_SSL_CA value needs to be different than the default values provided by PlanetScale
django-heroku to your
requirements.txt file. This will install the necessary packages when deploying to Heroku. If you are following along using the example provided, here is the updated
The Procfile in your project tells Heroku how it should start up the project. The file must be in the root of the project and not in a subdirectory. Here is the Procfile used to deploy the django-example project to Heroku:
web: gunicorn --chdir ./mysite mysite.wsgi --log-file -
After these steps have been completed, you may redeploy your application to Heroku. To view a complete example, please refer to the heroku-deployment branch of the sample repository. This concludes the guide on deploying a Django application to Heroku.