From f69ce6c2b322db37785d747e03cdafdf78939ab0 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Sat, 16 Jul 2005 16:07:04 +0000 Subject: [PATCH] django.conf.settings now fails loudly if DJANGO_SETTINGS_MODULE is broken in any way. git-svn-id: http://code.djangoproject.com/svn/django/trunk@105 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/conf/settings.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/django/conf/settings.py b/django/conf/settings.py index dda46dba2f..2e715696f7 100644 --- a/django/conf/settings.py +++ b/django/conf/settings.py @@ -18,15 +18,20 @@ for setting in dir(global_settings): if setting == setting.upper(): setattr(me, setting, getattr(global_settings, setting)) -# try to load DJANGO_SETTINGS_MODULE +# try to load DJANGO_SETTINGS_MODULE try: - mod = __import__(os.environ['DJANGO_SETTINGS_MODULE'], '', '', ['']) -except (KeyError, ImportError, ValueError): - pass -else: - for setting in dir(mod): - if setting == setting.upper(): - setattr(me, setting, getattr(mod, setting)) + me.SETTINGS_MODULE = os.environ["DJANGO_SETTINGS_MODULE"] +except KeyError: + raise EnvironmentError("Environemnt variable DJANGO_SETTINGS_MODULE is undefined." + +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) + +for setting in dir(mod): + if setting == setting.upper(): + setattr(me, setting, getattr(mod, setting)) # save DJANGO_SETTINGS_MODULE in case anyone in the future cares me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '')