Django and Settings Injection

Last Updated: 03 December 2012

django injection python

This article is a work in progress, or documents a feature that is not yet released to all users. This article is unlisted. Only those with the link can access it.

Table of Contents

On January 1, 2013, all Django applications will no longer have code automatically injected into


Having code automatically injected into your makes your deployment unportable, mysterious, and frustrating when you stray from the defaults.

The Python community values declarative syntax. As PEP 20 states:

Explicit is better than implicit.

It is also a 12 Factor violation:

Config varies substantially across deploys, code does not.

Your code should honor the DATABASE_URL environment variable no matter where it is deployed, not just on Heroku.

The dj-database-url module reads the DATABASE_URL environment variable and converts it to the configuration dictionary that Django requires.

To use it, add the following to requirements.txt:


And the following to the bottom of your

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

Try it out today

You can disable settings injection today by adding a file to your repository:

$ touch .heroku/injection_disabled

If you don’t want to modify your repository, you can enable user-env-compile on your app and add the following config:

$ heroku labs:enable user_env_compile
$ heroku config:add DISABLE_INJECTION=1

We recommend testing this on your Django applications before January 1, 2013.