Open In App

How to Deploy a Django Application to Heroku with Git CLI?

Django is a popular web Framework of Python. It is based on MVT(Model-View-Template). MVT is a software design pattern for developing a web application. For more details about Django visit the Django tutorial.

Deploying Django project using Heroku here is two methods:



  1. Deploying Django project on Heroku using CLI 
  2. Deploying Django project on Heroku using Git CLI

For more details about the First method visit the Deploy Django project on Heroku using CLI

Here we discuss the second method How to deploy Django project on Heroku using Git CLI, It contains both the Project side Heroku sidestep:



Project Side Setup:

Follow the below steps to deploy your Django project to Heroku using Git CLI:

Step 1: For Heroku Deployment First we need to install dependencies [library] :

  1. Django-Heroku
  2. gunicorn
  3. whitenoise (It help to connect your project with the server)

Note: Dependencies are always dependent on the project, here mentioned dependency has commonly used in Django apps when you deploy a project on Heroku. For installing dependencies you used the pip command :

pip install <library name> 

Step 2: Create required files.

Heroku basically required two files Procfile and requirements.

web: gunicorn <project name>.wsgi --log-file -

Run following command in cmd:

pip freeze > requirements.txt 

Step 3: Update setting.py file

import django_heroku
DEBUG = FALSE
ALLOWED_HOSTS = ["*"] also you pass the url link of the project 
                    OR
ALLOALLOWED_HOSTS = ["https://elitebatch.herokuapp.com/"]
"whitenoise.middleware.WhiteNoiseMiddleware"
django_heroku.settings(locals())

Step 4: Upload your project on GitHub.

Heroku Side Setup: 

  1. First of all, create Heroku Account.
  2. Create an app on Heroku 
  3. Add python build pack
  4. Link your Heroku app with the Github repository – go to your app Heroku desktop and go to the deploy tab select deployment method (Github). After successfully connecting with the deployment method scroll down and search the repository that you want to connect with your app.
  5. After Linking with Github, choose the branch, Heroku gives us two methods either manually or turn on automatic deployment 

Great You have successfully uploaded your project on Heroku using git CLI. Project Live on Heroku and source code are available at https://github.com/vikash98k/elite_batch_article/tree/master/elite_batch Github

Article Tags :