How To Deploy a Django Application to Heroku with Git CLI? (original) (raw)

Last Updated : 9 May, 2026

Heroku is a platform-as-a-service (PaaS) for deploying, managing, and scaling applications. There are two ways to deploy a Django project on Heroku:

This section explains how to deploy a Django project to Heroku using Git CLI, covering both project setup and Heroku configuration.

Prerequisites

Before you begin, make sure you have:

Steps to Deploy Django Application to Heroku

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

Step 1: Install Required Dependencies

Install the essential libraries needed for deployment:

Run:

pip install gunicorn whitenoise dj-database-url

**Note: Additional dependencies may be required depending on your project.

Step 2: Create Required Files

web: gunicorn <project_name>.wsgi

pip freeze > requirements.txt

**Step 3: Update setting.py

Disable Debug Mode

DEBUG = FALSE

Configure Allowed Hosts

ALLOWED_HOSTS = [".herokuapp.com"]

Add WhiteNoise middleware

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
...
]

Configure Static Files

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

Configure Database (PostgreSQL).

import dj_database_url
DATABASES = {
'default': dj_database_url.config(conn_max_age=600, ssl_require=True)
}

Step 4: Prepare Your Project for Deployment

Initialize Git (if not already done):

git init

git add .

git commit -m "Initial commit"

Step 5: Set Up Heroku

You can then choose:

Step 7: Deploy Using Git CLI

heroku login

heroku create

git push heroku main

Step 8: Run Migrations

heroku run python manage.py migrate

Step 9: Open Your Application

heroku open

Optional: Collect Static Files

If needed, run:

heroku run python manage.py collectstatic

Final Notes

heroku logs --tail