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
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.