https://devcenter.heroku.com/articles/django
This quickstart will get you going with a Python/Django application that uses
- a Postgres database
- deployed to Heroku
Prerequisites
- Heroku toolbelt
- Python and Virtualenv
- Postgres
$ mkdir hello && cd hello
$ virtualenv venv --distribute
$ source venv/bin/activate
https://goshawknest.wordpress.com/2011/02/16/how-to-install-psycopg2-under-virtualenv/
$ sudo apt-get install libpq-dev python-dev
$ pip install django psycopg2 dj-database-url
Check that everything is setup correctly
$ django-admin.py startproject hello .
$ python manage.py runserver
If it is, then freeze the requirements
$ pip freeze > requirements.txt
Add the following to your settings.py:
import dj_database_url
DATABASES = { 'default': dj_database_url.config() }
Export the following environment variable with the following details (N.B. Can be put in venv/bin/activate since its already ignored by .gitignore)
export DATABASE_URL="postgres://user:pass@address:port/dbname"
Contents of .gitignore
*.pyc
*.tar.gz
venv
Initial commit
$ git init
$ git add .
$ git commit -m "Initial commit"
$ heroku create
$ heroku apps:rename hello # if you want to change the random name that Heroku gives you initially
$ heroku keys:add # required on first push
$ git push heroku master && heroku open