Last Updated: February 25, 2016
·
500
· keithio

Simple settings in Django

Background

As I beef up my Django skill set, I have been playing with different deploy options. At the moment, I'd rather use a PaaS than roll my own server and have to manage security and updates. Like many people, I love Heroku. This is a (very) simple method to change settings between a local and production environment.

Code

settings.py

import os
...
if os.environ.get('PRODUCTION', False):  # check if $PRODUCTION is True
    # Production server configurations go here
    ...
else:
    # Development server configurations go here
    ....

Clean and super easy.

Supplemental notes

This configuration is not Heroku specific. If you are running your own server, you can simply add an environment variable using the following.

export PRODUCTION=True