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:
- 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 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] :
- 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.
- 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
ALLOALLOWED_HOSTS = ["https://elitebatch.herokuapp.com/"]
- 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:
- 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 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!