How to Deploy a Django App to Heroku in 2018… The Easy Way

Rafeh Qazi
2 min readAug 11, 2018

--

Photo by Max Nelson on Unsplash

God damn, why does deploying your app on the web have to be SO difficult? Years into my experience as a software developer and to this day I find hosting online to be a PAIN.

If you ever tried it, did you enjoy running into issues with static files, WhiteNoise, not installing the middleware in the right location, or a whole host of said fun stuff? Yeah, me neither.

Well, not anymore my child. It’s still a little annoying but there is a MUCH simpler solution thanks to Django 2.0 ❤.

Here’s how you do it…

Step 1. Create a Procfile in your project root.

Procfile

web: gunicorn project_name.wsgi

Step 2. Do this in your app/settings.py

app/settings.py

import django_heroku # Then all the way at the bottom of the file
# ...
django_heroku.settings(locals())

UPDATE (Aug 3rd, 2019): Before you continue… You’ll need to have psycopg2 installed. To do this… The easiest way is to install something like pgAdmin on your Mac OS X from a GUI installer.

Step 3. Go to the command line and install psycopg2

pip install psycopg2

And NOW… you’ll be able to install django-heroku .

STEP 4. Install Django Heroku & push to master.

pip install gunicorn
pip install django-heroku
pip freeze > requirements.txt
# login to your heroku
heroku login
# create new app if one doesn't yet exist
heroku create
# create a new postgres database for your app
heroku addons:create heroku-postgresql:hobby-dev
# migrate your database to the heroku app
heroku run python manage.py migrate
# before you do this, make sure to add your SECRET_KEY to your env variables in your heroku app settings
git add .
git commit -m "Ready to heroku this sucker in the face."
git push heroku master

That’s it. BOOM. Your app is now online. You’re welcome.

Now, go ahead and clap for this article, please. Thank you.

--

--