Skip to content

Instantly share code, notes, and snippets.

@danielwaterworth
Created March 14, 2018 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielwaterworth/6b24aa553cb96cfe7a23b907e2b832e8 to your computer and use it in GitHub Desktop.
Save danielwaterworth/6b24aa553cb96cfe7a23b907e2b832e8 to your computer and use it in GitHub Desktop.

Heroku Python

Step 0 - requirements file

Make sure you have your dependencies in your requirements file. (The arrow is a bash thing, it may not work on windows. We want the output from pip freeze into requirements.txt).

pip freeze > ./requirements.txt

Step 1 - Django-Heroku

pip install django-heroku
pip freeze > ./requirements.txt

Add these lines to the end of settings.py:

import django_heroku
django_heroku.settings(locals())

Step 2 - Set STATIC_ROOT

in settings.py add:

STATIC_ROOT = 'static'

or similar (I didn't try to serve any static files).

Step 3 - Create a Procfile

Install gunicorn to serve the app.

pip install gunicorn
pip freeze > ./requirements.txt

Create a file in the root directory called Procfile:

web: gunicorn mysite.wsgi

Replace mysite with the name of your main app.

Step 4 - Push to heroku

Follow heroku's instructions for installing the commandline interface, then:

heroku login
heroku git:remote -a heroku_app_name
git push heroku master -u

Step 5 - DB Setup

heroku run ./manage.py migrate
heroku run ./manage.py createsuperuser

Step 6 - Troubleshoot

heroku logs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment