Deploying your Django 2 app to Heroku 2018 — Python 3

Abedy Ng'ang'a
2 min readJan 14, 2019

So after making a couple of apps I decided to go deploying with Heroku. At first it was a bit hectic but then I came around to finding a very basic and direct solution. First things first, It doesn’t matter whether you used SQLite, MySQL, PostgreSQL, or whatever database in your Django app, with the django_heroku package everything comes as easy as it will ever be. So let’s get started.

First you are gonna need git, heroku CLI, a virtual environment and a heroku account. After activating your virtual environment you’ll need to install the following packages in addition to the packages required by your Django app.

pip install gunicorn
pip install django_heroku

The django_heroku package is what does all the magic , including changing your settings to production mode. The next thing is to add the packages to our requirements file. To do that we’ll do the following command at the root of the project with our virtual environment activated.

pip freeze > requirements.txt

This will create a requirements file which will be used by Heroku to install the necessary packages required for our app. Next we’ll create a file named Procfile in the root of our project with the following line in it

web: gunicorn your-project-name.wsgi

So you’ll change your project name appropriately. Next we’ll open our settings.py file and add the following lines

#At the top
import django_heroku
#Then at the Bottom..
django_heroku.settings(locals())

And boom! we’re ready to start deploying.

So login with your heroku CLI

heroku login

Then add git to your project.

git init
git add .
git commit -m "Whatever message you want to set"

Then we’ll create a heroku app

heroku create your-app-name

Then set the heroku remote

heroku git:remote -a your-app-name

And finally

git push heroku master

And we’re done, just like that. Please give this article as many claps as possible. Hope you solved your deploying problems

--

--