Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

django.conf.settings now fails loudly if DJANGO_SETTINGS_MODULE is br…

…oken in any way.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@105 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f69ce6c2b322db37785d747e03cdafdf78939ab0 1 parent b4168db
Jacob Kaplan-Moss authored July 16, 2005

Showing 1 changed file with 13 additions and 8 deletions. Show diff stats Hide diff stats

  1. 21  django/conf/settings.py
21  django/conf/settings.py
@@ -18,15 +18,20 @@
18 18
     if setting == setting.upper():
19 19
         setattr(me, setting, getattr(global_settings, setting))
20 20
 
21  
-# try to load DJANGO_SETTINGS_MODULE 
  21
+# try to load DJANGO_SETTINGS_MODULE
22 22
 try:
23  
-    mod = __import__(os.environ['DJANGO_SETTINGS_MODULE'], '', '', [''])
24  
-except (KeyError, ImportError, ValueError):
25  
-    pass
26  
-else:
27  
-    for setting in dir(mod):
28  
-        if setting == setting.upper():
29  
-            setattr(me, setting, getattr(mod, setting))
  23
+    me.SETTINGS_MODULE = os.environ["DJANGO_SETTINGS_MODULE"]
  24
+except KeyError:
  25
+    raise EnvironmentError("Environemnt variable DJANGO_SETTINGS_MODULE is undefined."
  26
+
  27
+try:
  28
+    mod = __import__(me.SETTINGS_MODULE, '', '', [''])
  29
+except ImportError, e:
  30
+    raise EnvironmentError("Could not import DJANGO_SETTINGS_MODULE '%s' (is it on sys.path?): %s" % (me.SETTINGS_MODULE, e)
  31
+
  32
+for setting in dir(mod):
  33
+    if setting == setting.upper():
  34
+        setattr(me, setting, getattr(mod, setting))
30 35
 
31 36
 # save DJANGO_SETTINGS_MODULE in case anyone in the future cares
32 37
 me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '')

0 notes on commit f69ce6c

Please sign in to comment.
Something went wrong with that request. Please try again.