Lab 6 - Heroku

Deploy the Django application created in Lab 4 to Heroku. Understand the reasoning behind Platform as a Service (PaaS) businesses like Heroku. You may follow the official documentation.

Setting up the Heroku CLI

Sign up for a free Heroku account at

Download and install the Heroku CLI tools.

tar -xvf heroku-linux-x64.tar.gz
export PATH="$PATH:$HOME/heroku/bin"

Ensure the heroku tool works, login to your account.

heroku --version
# heroku/7.19.4 linux-x64 node-v11.3.0
heroku login

Deploying our Django Application

Ensure the Django application created in Lab 4 is working locally.

Activate the virtualenv for the Django application.

Ensure that the current working directory is similar to the following.

$ tree 
├── db.sqlite3
├── mysite
│   ├──
│   ├──
│   ├──
│   └──
└── polls
    ├── migrations
    │   ├──
    │   ├──
    │   └── __pycache__
    │       ├── 0001_initial.cpython-37.pyc
    │       └── __init__.cpython-37.pyc

Pip install gunicorn and django-heroku.

pip install gunicorn django-heroku

Save the new python requirements into the requirements.txt file.

pip freeze > requirements.txt

Create a new file named Procfile for Heroku applications.

web: gunicorn mysite.wsgi

Within mysite/, add the following statements:

import django_heroku # top of the file

# ...

django_heroku.settings(locals()) # bottom of the file

Commit your files and deploy the application using a git integration.

What happens when you go to /polls on your Heroku deployed site?

Run your migrations, create a Superuser, and ensure your application functionality works.

$ heroku run --app APPNAME python migrate
$ heroku run --app APPNAME python createsuperuser

Question 1: What are some ways you can deploy your code to Heroku?

Question 2: What is a Procfile used for?

Question 3: What is the link to your deployed application (on herokuapps)?

Optional: Configure TravisCI or CircleCI for a deployment pipeline that utilizes tests.