I decided to take a peek into Django world and while playing around with tutorial project I decided to use also git for version control.
As basic Django project layout is following:
project/
__init__.py
manage.py
settings.py # < -- Contains sensitive information
urls.py
Where settings.py contains sensitive information like usernames/passwords and other data one doesn’t actually want to save in the repository.
But fortunately it’s possible to use external configure file which is included by main configuration file and thanks to Python’s clever exception system, or ImportError exception, we can simply make following modification to settings.py:
diff --git a/project/settings.py b/project/settings.py
index 641c97f..9019d9e 100644
--- a/project/settings.py
+++ b/project/settings.py
@@ -84,4 +84,9 @@ INSTALLED_APPS = (
'django.contrib.sites',
)
-
+
+try:
+ import sys
+ from settings_local import *
+except ImportError, e:
+ print "Unable to load local settings: %s" % e
+ sys.exit(1)
Then we create settings_local.py which contains all these defines you do not want to appear inside the repository.