Created
April 20, 2012 19:24
-
-
Save drinks/2431175 to your computer and use it in GitHub Desktop.
Heroku-compatible local settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Define any global settings here | |
FOO = 'bar' | |
# Import local settings or from os.environ | |
try: | |
from myapp.local_settings import * | |
except ImportError: | |
import imp | |
import os | |
import sys | |
try: | |
with open(os.path.join(os.path.dirname(__file__), 'local_settings.example.py'), 'rb') as fp: | |
for key in imp.load_module( | |
'example_settings', fp, 'local_settings.example.py', | |
('.py', 'rb', imp.PY_SOURCE) | |
).__dict__.keys(): | |
if os.environ.get(key) is not None: | |
setattr(sys.modules[__name__], key, os.environ.get(key)) | |
except Exception, e: | |
raise ImportError('Got %s trying to initialize settings.' % e) | |
finally: | |
del sys.modules[__name__].imp | |
del sys.modules[__name__].os | |
del sys.modules[__name__].key | |
del sys.modules[__name__].fp | |
del sys.modules[__name__].sys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes you have local_settings.example.py in the same directory with a bunch of empty settings.