Heroku aka infrastructure at your fingertips, a cloud platform as a service that allows you to just focus on your application. This is enhanced by the many add-ons available (e.g databases, logging, etc). Getting a Django project up and running on Heroku is easy and painless.
Account and toolbelt
- Create an account on Heroku.
- Download and install the Heroku toolbelt. This is the command line interface(CLI) to Heroku.
Create application in cloud
- In the terminal (shell), Navigate to your local Django project’s root (same level as requirements.txt).
- Login into heroku –
- Create an app on Heroku –
heroku create appname
- Go to your Heroku app dashboard
- Provision a database add on (choose a database of your liking like Postgres or MySQL)
- Select the new provisioned add-on (above) then create a database
- Take note of the connection information of the newly created database then update the settings.py file in your local Django application
Side Note:There are many other add-ons for Heroku to support your application. I recommend browsing through them to see whats available to you.
Create a file named Procfile in the root of your local Django application. The Procfile is what tells Heroku what process type and how many you want to run on you app. In this case you want a web process to serve your application. Heroku currently gives 1 web and 1 worker (task runner process) on their free tier.
- Create Procfile with they following code
web: gunicorn appname.wsgi
- Ensure gunicorn package is included in your requirements.txt e.g
Side Note: Procfile has a capital P.
- Deploy to heroku –
git push heroku master
- Now you can visit your live running app – http://appname.herokuapp.com
Side note: Deploy a specific branch to Heroku via:
git push heroku specific-branch:master