This page looks best with JavaScript enabled

Deploy Django on heroku with postgres

 ·   ·  β˜• 2 min read

Python Heroku Deployment

Steps to create a postgres database and deply a Python app to Heroku

Install Postgres dependencies

pip install psycopg2

Install guinicorn locally

pip install gunicorn

Install Heroku CLI

Login via CLI

heroku login

Create app

heroku create appname

Create database

heroku addons:create heroku-postgresql:hobby-dev --app appname

or you can create from dashboard and add the details to


heroku config --app appname

# Add to your app

Create Procfile at the root

touch Procfile
# Add this
web: gunicorn project_name.wsgi


echo "web: gunicorn mysite.wsgi --log-file -" > Procfile

Create requirements.txt

pip freeze > requirements.txt

Create runtime.txt

touch runtime.txt

# Add this

Add your hostname to the list of allowed hosts in



STATIC_URL = '/static/'
# static root
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

Add the static urls in of the project

from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
    # ... the rest of your URLconf goes here ...
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Collect Django static assets

python collectstatic

put the static folder at the root of your project

Deploy with Git

git init
git add . && git commit -m 'Deploy'
heroku git:remote -a appname
git push heroku master

Add table to remote database

heroku run bash
python migrate
python createsuperuser

See heroku logs

heroku logs --tail

Visit app

heroku open

Ohidur Rahman Bappy
Ohidur Rahman Bappy
πŸ“šLearner 🐍 Developer