Skip to content

Instantly share code, notes, and snippets.

@ecarter
Created May 9, 2010 23:10
Show Gist options
  • Save ecarter/395486 to your computer and use it in GitHub Desktop.
Save ecarter/395486 to your computer and use it in GitHub Desktop.
Manage Multiple Django Settings Environments
# Manage Multiple Settings Environments
# From Eric Florenzano's "Handling Development, Staging, and Production Environments"
# Link: http://djangodose.com/articles/2009/09/handling-development-staging-and-production-enviro/
#
# In shell
#
# $: export FLAVOR=dev
# $: ./manage.py runserver
#
# In wsgi file:
#
# import os
# import django.core.handlers.wsgi
# os.environ['FLAVOR'] = 'prod'
# os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
# application = django.core.handlers.wsgi.WSGIHandler()
#
# the following goes in the bottom of your settings.py:
import os
import sys
FLAVOR = os.environ.get('FLAVOR', 'local')
def override_settings(dottedpath):
try:
_m = __import__(dottedpath, fromlist=[None])
except ImportError:
pass
else:
_thismodule = sys.modules[__name__]
for _k in dir(_m):
setattr(_thismodule, _k, getattr(_m, _k))
override_settings('project.conf.' + FLAVOR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment