Ole Morten Halvorsen

March 10, 2008
Separating Development and Production Settings in Django

Django does not have a built-in way of having development only settings. Luckily for us, Django settings is nothing but a simple python module. This allows us to implement our own way of dealing with settings right in the settings.py file.

On This Week in Django episode 4 (great podcast!), Michael Trier featured a Tip of the Week on how to implement development only settings. Since I like to have everything checked in to my Mercurial repository, I extended the code to allow local settings to exists on my production server without being loaded.

The original version.

1
2
3
4
5
[..]
try:
    from local_settings import *
except ImportError, exp:
    pass

My version.

1
2
3
4
5
6
7
[..]
import socket
if not socket.gethostname() == "omh.cc":
    try:
        from local_settings import *
    except ImportError, exp:
        pass

It’s very simple. All it does is to check the host name and only import local_settings.py if host name is not “omh.cc”, which is the name of my server.

Leave a comment

Commenting has been disabled. This entry was posted more than 2 weeks ago.

Created by Ole Morten Halvorsen.   Powered by Django.