Heroku Django Deployment

Educational Technology and ICT

Created with Sketch.

Heroku Django Deployment

Heroku is a cloud platform as a service supporting several programming languages. One of the first cloud platforms, Heroku has been in development since June 2007, when it supported only the Ruby programming language, but now supports Java, Node.js, Scala, Clojure, Python, PHP, and Go.

These are the steps in deploying a Django app on heroku

hosting a Django app on heroku

go to the app opened in vscode
make sure you are on the Django project main directory(one with manage.py)

pip install gunicorn whitenoise

touch requirements.txt

touch Procfile

web: gunicorn projectname.wsgi --log-file -

touch runtime.txt


pip install dj_database_url

pip freeze > requirements.txt

make sure you set static root
at settings.py

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

under middleware add


under DATABASES = {

IN YOUR settings.py file

import dj_database_url
db_from_env = dj_database_url.config(conn_max_age=600)

also in setting.py
DEBUG = false
ALLOWED_HOSTS = ['projectHerokuname.herokuapp.com', '']

push the private repo to github

login to heroku account
create and app in heroku
go to heroku settings for the app to see the database credentials and put it as your database connections in the settings.py
also make sure you do add buildpack and select python python

go to heroku deploy for the app
make sure you are connected to github.com repo, so make sure you have a private github repo for the project

heroku run python manage.py makemigrations -a nameofapponheroku
heroku run python manage.py migrate -a nameofapponheroku

make sure you downloaded and installed heroku cli from the heroku website---heroku cli for windows os

from the heroku cli
heroku login
click into the cli empty space

if you have error when accesing your website on heroku

do the following
heroku logs --tail

it shows you the error

for postgres database deployment

after putting in the database credentials from heroku resources in the settings tab of your heroku app
put it onto the database connection in your projects settings.py under databases
  make sure your database connections are good for postgress on settings.py
  you can have many databse connections in our settings.py commented out

create superuser in heroku environment
heroku run python manage.py makemigrations
heroku run python manage.py migrate

we can push our postgres database to aws then connect to heroku. this will enable static files upload
check out on divy

aws heroku postgres

go to aws
create a aws account
go to ur account
put a credit card but use the free tier
sign in
under find or search
work with RDS

click on create database

select database- postgress

select free tier
set username and password


add additional connectivity

set public accessible to yes

work with all the default
the port no is 5432

additional configuration
initial database name  --  demo_1

click on create

click on databases to see it
you can modify the public accessibilty there

go to connectivity and setting and copy the endpoint

go to you pgadmin database for postgres or create a new database there for the app and rightclick the database and click on create new server
click on connections and fill in the credentials from your aws

go to the settings.py
in ue django app

at HOST put the endpoint copied from aws

go and makemigrations and migrate

push your code to github

thank you

Leave a Reply

Your email address will not be published. Required fields are marked *

Open chat