Skip to main content

django12factor: Bringing 12factor to Django

Project description Code Health Requirements Status Coverage Status

What is it?

Django is an awesome Python web framework.

The Twelve-Factor App” is an awesome methodology for building SaaS apps.

django-12factor makes Django more 12factor-y. Right now, this focuses on the Config - “Store config in the environment”; Heroku users with addons will be particularly familiar with this.

Still not sure of the benefits? Check out “Twelve-Factor Config: Misunderstandings and Advice”.


Add the following to the bottom of your

import django12factor
d12f = django12factor.factorise()

factorise() returns a dict of settings, so you can now use and assign them as you wish, e.g.

DEBUG = d12f['DEBUG']

If you don’t like that repetition, you can (ab)use globals() like so:

import django12factor
d12f = django12factor.factorise()

def f(setting):
    globals()[setting] = d12f[setting]


You can also add non-Django settings this way, e.g. keys to APIs:

custom_settings = (
d12f = django12factor.factorise(custom_settings=custom_settings)


In the event of a custom_setting not being set in the environment, it will default to None.

Give me everything!

If you say so…

import django12factor


django12factor.getenv_bool is a utility function that takes the name of an environment variable, and returns True _unless_ it is set to either a “falsey” string (e.g. "no") or not set.


The following settings are currently supported:


Defaults to False for safety reasons, otherwise True unless os.environ("DEBUG") is a “falsy” string.


As for DEBUG, but defaults to the value of DEBUG.


Uses django-cache-url to parse os.environ("CACHE_URL").


A static LOGGING dict that configures 12factor-style logging.


Uses dj-database-url - parses DATABASE_URL if it exists, otherwise falls back to in-memory sqlite.

Anything of the form FOO_DATABASE_URL will be parsed as DATABASES['foo'], allowing you to configure multiple databases via the environment.


Treats os.environ("ALLOWED_HOSTS") as a comma-separated list.


Uses os.environ("SECRET_KEY") - required if DEBUG==False.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django12factor, version 1.3
Filename, size File type Python version Upload date Hashes
Filename, size django12factor-1.3.tar.gz (4.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page