Managing local settings in Django

Posted by Christian on Aug 16 2007, 22:36 CEST
Tagged with Python, Django

Sometimes it is nice to be able to configure specific Django settings for a single host and not get tons of conflicts the next time you do svn up. I personally solve this by exploiting that the Django settings.py is nothing but Python code. At the last line of the file I do a:

from local_settings import *

That is, way I do a relative import from local_settings.py and gets every global symbol mixed into the current namespace, allowing me to overwrite every option. An example could be to configure the global settings.py to use sqlite as a database backend for the project, but in the production environment overwrite the DATABASE_* options in the local_settings.py. This goes as well for caching - not many developers run a PostgreSQL and memcached on their laptop.

To make sure that local_settings.py never is committed to the repo (and maybe compromising database passwords), it is a good idea to add it to the Subversion property svn:ignore:

svn propset svn:ignore local_settings.py /path/to/your/project

Furthermore, I usually put up a local_settings.py.dist with a couple of commented out examples for the developers of what could be done here.

Comments for "Managing local settings in Django"

Currently disabled.