How to deploy Python Django project to heroku?

Okan Özşahin
2 min readJun 4, 2021

Deploy python django project from local to heroku

for macOS intallation:

brew install heroku 

→ connect to your heroku account with your email and your password

heroku login

→ to create heroku-app

heroku create <your-app-name>

need to web WSGI HTTP Server so we can install gunicorn in the django project file

pip install gunicorn

→ need to add this file in the django project file because of heroku define this file as configuration

Procfile(in this file define a applications path)

web: gunicorn <your wsgi.py directory>.wsgi — log-file -

to deploy the app, all required libraries is been writing in requirements.txt that are used by django-project:

pip freeze > requirement.txt

runtime.txt → python-3.9.5 (look supported python version to heroku-django)

You can find explanation as video with Turkish language:

→ in project directory with bash

git initgit add .git commit -m “<your messages>”git push heroku master

→ connect to remote heroku.git repo

heroku git:remote -a <project_name>

→ if you have static file at your project

pip install django-heroku

**Be sure to add “django-heroku” to your requirements.txt file as well.

Add the following import statement to the top of settings.py:

import django_heroku

Then add the following to the bottom of settings.py:

# Activate Django-Herokudjango_heroku.settings(locals())

in settings.py:

ALLOWED_HOSTS = [‘<your-heroku-app-name>’]ALLOWED_HOSTS = [‘mech-meet.herokuapp.com’]

If “ProgrammingError at / relation “…” does not exist” error is occurred then you can do steps below:

do those in django your project with bash:

heroku run bash~$ python3 manage.py makemigrations~$ python3 manage.py migrate~$ exit

Author

Okan Özşahin

LinkedIn — https://www.linkedin.com/in/okan%C3%B6z%C5%9Fahin/

Email — okan.ozsahin@innology.com

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Okan Özşahin
Okan Özşahin

Written by Okan Özşahin

Backend Developer at hop | Civil Engineer | MS Computer Engineering

No responses yet

Write a response