Skip to content

Instantly share code, notes, and snippets.

@kogakure
Forked from trey/django_2012.md
Created May 5, 2012 09:41
Show Gist options
  • Save kogakure/2601205 to your computer and use it in GitHub Desktop.
Save kogakure/2601205 to your computer and use it in GitHub Desktop.
Bash: How to start a Django project in 2012

How to start a Django project in 2012

(and deploy to Heroku)

First, warm up your system.

$ easy_install pip
$ pip install virtualenv
$ pip install django
$ gem install heroku

Start a project.

$ django-admin.py 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

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 settings.py.

INSTALLED_APPS = (
    'south',
    ...

Setup SQLite for local development. Also in settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'development.sqlite',
        ...

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

$ chmod +x manage.py

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

Now go make something awesome.

Deploy to Heroku

$ heroku create --stack cedar
$ git push heroku master
$ heroku run python manage.py syncdb
$ heroku open

Update your database with South and push the changes to Heroku

  1. Make changes to your models
  2. $ ./manage.py schemamigration [appname] --auto
  3. $ ./manage.py migrate [appname]
  4. [commit & push changes to heroku]
  5. $ heroku run ./manage.py 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:

$ ./manage.py syncdb
$ ./manage.py migrate [appname]

Finally, fire up your server:

$ ./manage.py runserver

Sources

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