Deploying Django App on Heroku From Github Repository

02 August 2020

Image Source: vschool.io

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 an option to connect our github repository and then it automatically triggers a build and deploy 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

First step would be creating an account on heroku and creating an app for your django application.

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

2. Connecting 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 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.

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.

Happy Coding !!!