diff --git a/django/conf/settings.py b/django/conf/settings.py index 6f03d1c202..29b8f043aa 100644 --- a/django/conf/settings.py +++ b/django/conf/settings.py @@ -10,6 +10,8 @@ import os import sys from django.conf import global_settings +ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" + # get a reference to this module (why isn't there a __module__ magic var?) me = sys.modules[__name__] @@ -20,14 +22,16 @@ for setting in dir(global_settings): # try to load DJANGO_SETTINGS_MODULE try: - me.SETTINGS_MODULE = os.environ["DJANGO_SETTINGS_MODULE"] + me.SETTINGS_MODULE = os.environ[ENVIRONMENT_VARIABLE] + if not me.SETTINGS_MODULE: # If it's set but is an empty string. + raise KeyError except KeyError: - raise EnvironmentError, "Environment variable DJANGO_SETTINGS_MODULE is undefined." + raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE try: mod = __import__(me.SETTINGS_MODULE, '', '', ['']) except ImportError, e: - raise EnvironmentError, "Could not import DJANGO_SETTINGS_MODULE '%s' (is it on sys.path?): %s" % (me.SETTINGS_MODULE, e) + raise EnvironmentError, "Could not import %s '%s' (is it on sys.path?): %s" % (ENVIRONMENT_VARIABLE, me.SETTINGS_MODULE, e) # Settings that should be converted into tuples if they're mistakenly entered # as strings. @@ -41,7 +45,7 @@ for setting in dir(mod): setattr(me, setting, setting_value) # save DJANGO_SETTINGS_MODULE in case anyone in the future cares -me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '') +me.SETTINGS_MODULE = os.environ.get(ENVIRONMENT_VARIABLE, '') # move the time zone info into os.environ os.environ['TZ'] = me.TIME_ZONE @@ -51,4 +55,3 @@ for k in dir(me): if not k.startswith('_') and k != 'me' and k != k.upper(): delattr(me, k) del me, k -