Open In App
Related Articles

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

Improve Article
Save Article
Like Article

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.

  • Procfile : procfile is created at file directory, procfile does not require any extension :
web: gunicorn <project name>.wsgi --log-file -
  • Requirement: The requirement file will store all the dependencies and their versions regarding the project.

Run following command in cmd:

pip freeze > requirements.txt 

Step 3: Update file

  • Import django_heroku at the top, it is the configuration of the Django application.
import django_heroku
  • Set DEBUG = False its hides the URL link at the dynamic side.
  • Add app URL in allowed hosts
ALLOWED_HOSTS = ["*"] also you pass the url link of the project 
  • Add whitenoise middleware 
  • Add static root (it is required when you use static storage in your project)
  • Add django_heroku setting at the last 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 Github

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 07 Mar, 2022
Like Article
Save Article
Similar Reads
Complete Tutorials