Deploying Django App on Heroku From Github Repository

Aman Chourasiya
Analytics Vidhya
Published in
3 min readAug 30, 2020

A simple and easy guide to automating your deployment on Heroku cloud

Deploying your Django application has never been easier as deploying on Heroku cloud platform. Heroku provides a seamless experience for deploying a web application. Heroku does one thing and does it well i.e. deploying web application with fewer steps.

Let’s take a look how Heroku deploys our application, it provides us with an option to connect our GitHub repository and then it automatically triggers a build and deploys our application with every code check-in, this way it provides a minimal CI/CD pipeline for our development process.

These are some key steps that should be followed while deploying your app on Heroku.

1. Creating a new app on Heroku

The first step would be creating an account on Heroku and creating an app for your Django application.

After creating the app on Heroku dashboard, we can start configuring our app.

2. Connecting the GitHub repository to Heroku.

Go to deploy tab and connect your GitHub repository with this app and Heroku will automatically detect our application by seeing some specific files.

3. Generating files specific to Heroku deployment.

In this above image, we can see that my GitHub repository is connected with this app. Heroku looks for two files in our repository root directory.

  1. requirements.txt — This is a list of all the requirements and external dependencies that our project will need before deployment.
  2. Procfile — This is a special file that is specific to Heroku and it has its own commands that Heroku needs to determine what command to run to start our app.
requirements.txt
=============================
asgiref==3.2.10
dj-database-url==0.5.0
Django==3.0.8
gunicorn==20.0.4
psycopg2==2.8.5
psycopg2-binary==2.8.5
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0
boto3==1.14.16
django-heroku==0.3.1
Pillow==7.2.0
Procfile
=======================
release: python3 portfolio/manage.py migrate
web: python3 scripts/start_server.py prod

First, Heroku will install all dependencies from requirements.txt and then will move on to Procfile.

In Procfile the command under release will be run before every deployment since we need to migrate our database before every deployment therefore this command is necessary.

The command under web is the command that should start our application and will receive web traffic. Since Heroku deploys our application inside a container called dyno in Heroku's term, it becomes necessary to note that our data will not persist across deployments.

4. Testing our app.

Heroku provides a logs console that displays all the deployment-related logs, we should go through these logs to confirm that our app is successfully deployed and we can go to the URL provide by Heroku to test if our app is working is excepted.

For more clarification please go through my GitHub repo to check directory structure and other changes for Heroku deployment.

This website is currently deployed on Heroku cloud platform.

Originally published at https://www.amanchourasiya.com.

--

--