How To Deploy a Django Application to Heroku with Git CLI?
Last Updated :
19 Jun, 2024
Deploying a Django application to Heroku using the Git command-line interface (CLI) is a simple process. Heroku provides a platform-as-a-service (PaaS) that enables you to deploy, manage, and scale your applications easily. This guide will walk you through the steps to deploy your Django application to Heroku using Git CLI.
Deploying Django project using Heroku here are two methods:
- Deploying Django project on Heroku using CLI
- 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 a Django project on Heroku using Git CLI, It contains both the Project side Heroku sidestep:
Steps to Deploy Django Application
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] :
- Django-Heroku
- gunicorn
- 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 manage.py 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 setting.py 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.
DEBUG = FALSE
- Add app URL in allowed hosts
ALLOWED_HOSTS = ["*"] also you pass the url link of the project
OR
ALLOALLOWED_HOSTS = ["https://elitebatch.herokuapp.com/"]
- Add whitenoise middleware
"whitenoise.middleware.WhiteNoiseMiddleware"
- 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())
django_heroku.settings(locals())
Step 4: Upload your project on GitHub.
Heroku Side Setup:
- First of all, create Heroku Account.
- Create an app on Heroku
- Add python build pack
- 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.
- 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
Similar Reads
How to Deploy Django application on Heroku ? Django is an MVT web framework used to build web applications. It is robust, simple, and helps web developers to write clean, efficient, and powerful code. In this article, we will learn how to deploy a Django project on Heroku in simple steps. For this, a Django project should be ready, visit the f
4 min read
How to Deploy Django Application in AWS EC2? In this article, we will study how we can deploy our existing Django web application to Windows Server in AWS EC2. We will also see how to use the public IP of the EC2 instance to access the Django application. For this article, you should know about setting up EC2 in AWS. We will see how to deploy
3 min read
Deploying a Django App to Heroku Using Github Repository Heroku is a free hosting cloud service provider. We can use our free dynos to deploy our applications on the cloud. The only disadvantage is that it loses all the data once the app sleeps and it cannot handle multiple requests at a time when hosted on free dynos. First of all, to proceed further you
2 min read
How to Deploy a Django Application in Kubernetes In this article, we will study how we can deploy Django web applications to Kubernetes. We will also see how to dockerize and build an image of the Django application using Dockerfile. For this article, you should know about setting up a VM in Azure. We will see how to deploy applications on Linux S
5 min read
How to Deploy a Web Application on GCP? Google Cloud Platform is one of the cloud service providers that provide various cloud services for a seamless experience. It provides various services like storage, networks, development tools, Analytics tools, infrastructure, and many more. Benefits Of Deploying Web Applications on Google Cloud Pl
4 min read
Deploying Django App on Heroku with Postgres as Backend Django is a high-level Python web framework used to create web applications without any hassle, whereas, PostgreSQL is a powerful, open-source object-relational database. Let us first create a Django application with PostgreSQL in the backend and deploy it in Heroku which is a container-based cloud
5 min read
How to Dockerize django application for production deployment with Gunicorn and Nginx Docker is an open-source containerization platform used for building, running, and managing applications in an isolated environment. A container is isolated from another and bundles its software, libraries, and configuration files. Django is an open-source Python web framework that can be used to qu
5 min read
How to Deploy Django Application in AWS Lambda? Pre-requisite: AWS , Python Django is a Python web framework that makes it easy to build web applications quickly and securely. It has a large and helpful community that provides support and contributes to its development. AWS Lambda is a serverless computing platform that runs your code in Docker c
7 min read
How to Deploy a Golang WebApp to Heroku? Go, also known as "Golang," is gaining popularity among DevOps professionals in recent years. There are many tools written in Go, including Docker and Kubernetes, but they can also be used for web applications and APIs. While Golang can perform as fast as a compiled language, coding in it feels more
5 min read
Deploy an ASGI Django Application ASGI, which stands for Asynchronous Server Gateway Interface, is a big deal in Django. It basically helps Django handle lots of things at once, like requests from users. Instead of waiting for one thing to finish before starting the next, ASGI lets Django do multiple tasks simultaneously. It's like
5 min read