Creating and including local settings in Django

We can include our local_settings.py at the end of settings.py as follows:

#settings.py
try:
    execfile(os.path.join(os.path.dirname(__file__), "local_settings.py"))
except IOError:
    pass

We create local_settings.py in the same directory. An example is below:

#local_settings.py
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "w3mentor",
        "USER": "root",
        "PASSWORD": "",
    }
}

Enjoyed this post? Share it!