Django project layout for Heroku

By: José Padilla

At Blimp we love working with Django. We use it for almost all of our projects, including Blimp and -M.

In Django 1.4, the startproject and startapp commands came with a new template option. Specifying this --template option lets you use a custom project directory structure for your project from a path or URL. By default when you run the startproject management command, it creates a Django project directory structure that contains and a project package (containing a and other files) based on this default template.

We decided to create a project template with the things we always end up doing on our Django projects. This template has a couple of useful settings and Fabric commands that make deploying, managing, and using Django with Heroku easier.

How to install startproject --template= --extension=py,md,dev project_name

What’s included?

  • Fabric – Fabric is a Python library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
  • South – schema and data migrations for Django
  • dj-database-url – Django utility allows you to utilize the DATABASE_URL environment variable to configure your Django application.
  • django-extensions – Custom management extensions for the Django
  • gunicorn – Simply implemented, light on server resource usage, and fairly speedy Python WSGI HTTP Server.
  • psycopg2 – PostgreSQL database adapter for Python

Fabric Script
Fabric is definitely the easiest way to execute local and remote shell commands. We’ve created quite a few of these to help with deployment, database management, and Heroku, all aware of the environment, so for example, you can easily run database migrations in development, staging, or production.

You can keep track of the project on GitHub. Follow me (jpadilla) on GitHub.

6 thoughts on “Django project layout for Heroku”

  1. This is great! I’ve been working on a Fabfile based on heroku needs that I was planning on releasing, but you got there first! And I’d completely forgotten about the template option for Django, so thanks for the reminder. The alternative to load the correct environment settings is a nice touch too.

    Good work!

      1. Yes, exactly. You can create a shortcut function with env = os.environ.get. Then all you need to get the env variable in is

        MY_SETTING = env(‘MY_SETTING’, ‘default’)

        For boolean values you can use something like this:

        DEBUG = env(‘DEBUG’, ‘false’).lower() in [‘true’, ‘yes’, ‘t’, ‘y’, ‘1’, ‘on’, ‘enabled’]

Leave a Reply