Skip to content
Create a gist now

Instantly share code, notes, and snippets.

@trey /
Last active Jan 27, 2016

How to start a Django project in 2012

This is a little out of date. Be sure to check the Heroku docs for the latest and greatest.

How to start a Django project in 2012

(and deploy to Heroku)

First, warm up your system.

$ easy_install pip (may need sudo)
$ pip install virtualenv (may need sudo)
$ pip install django (may need sudo)
$ brew install postgresql

Then be sure to follow the instructions for finishing the postres setup.

Start a project.

$ startproject [myproject]
$ cd !$

Setup virtualenv and start it up.

$ virtualenv --no-site-packages ve
$ source ve/bin/activate

(ve for virtualenv. Isn't that nice and terse? You can call it whatever you want.)

Install some things into your virtualenv.

$ pip install Django psycopg2 south dj-database-url

Now load the exact version into a requirements.txt file.

$ pip freeze > requirements.txt

(psycopg2 is a PostgreSQL adapter for Python.)

Put south in your INSTALLED_APPS in


Make executable (so you don't have to type python ... all the time).

$ chmod +x

Don't forget to add ve to your .gitignore file.

Database settings for local development and Heroku

Create a database for local use.

createdb [whatever]

Add the following to the end of your file:

import dj_database_url
DATABASES = {'default': dj_database_url.config(default='postgres://localhost/[whatever]')}

If you want to sync your local database with Heroku, see this post.

Now go make something awesome.

Deploy to Heroku

$ heroku create
$ git push heroku master
$ heroku run ./ syncdb
$ heroku open

Update your database with South and push the changes to Heroku

  1. Make changes to your models
  2. $ ./ schemamigration [appname] --auto
  3. $ ./ migrate [appname]
  4. [commit & push changes to heroku]
  5. $ heroku run ./ migrate [appname]

Working on your project later

Whenever you work on your project, you'll want to activate your virtualenv:

$ source ve/bin/activate

Then load any new requirements:

$ pip install -r requirements.txt

Sync and/or migrate your database:

$ ./ syncdb
$ ./ migrate [appname]

Finally, fire up your server:

$ ./ runserver


trey commented May 26, 2012

This is a Solutions Log post.


why are you install django at the system level and at the virtualenv level?

trey commented Oct 19, 2012

@binarydud, Just for the initial setup of a new project. Not necessary, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.