Created
October 19, 2012 11:04
-
-
Save haoch/3917584 to your computer and use it in GitHub Desktop.
django settings : automatically load settings arguments from certain package and set as locals variables
This file contains 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
""" Automatically load settings arguments from environment settings and set as locals variables | |
* os.environ.get('DJANGO_CONF', 'default') | |
Author : Hao Chen ([email protected]) """ | |
DJANGO_CONF = os.environ.get('DJANGO_CONF', 'default') | |
if DJANGO_CONF != 'default': | |
module = __import__(DJANGO_CONF, globals(), locals(), ['*']) | |
for k in dir(module): | |
locals()[k] = getattr(module, k) |
This file contains 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
""" Automatically load settings arguments from certain package and set as locals variables | |
Author: Hao Chen ([email protected]) """ | |
import inspect | |
import pkgutil | |
for _, module_name, _ in pkgutil.walk_packages(__path__): | |
module = __import__(module_name, globals(), locals(), []) | |
for var_name, val in inspect.getmembers(module): | |
if var_name.isupper(): | |
locals().update({var_name: val}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment