Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cleaned up code in django.conf.settings to move DJANGO_SETTINGS_MODUL…

…E into a variable, so other scripts can introspect it. Also made it display a better error message if DJANGO_SETTINGS_MODULE is set to the empty string

git-svn-id: http://code.djangoproject.com/svn/django/trunk@239 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 45c334dd8bf9945e745a68b1199c2e536a3274d3 1 parent 584cab7
Adrian Holovaty authored July 20, 2005

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

  1. 13  django/conf/settings.py
13  django/conf/settings.py
@@ -10,6 +10,8 @@
10 10
 import sys
11 11
 from django.conf import global_settings
12 12
 
  13
+ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
  14
+
13 15
 # get a reference to this module (why isn't there a __module__ magic var?)
14 16
 me = sys.modules[__name__]
15 17
 
@@ -20,14 +22,16 @@
20 22
 
21 23
 # try to load DJANGO_SETTINGS_MODULE
22 24
 try:
23  
-    me.SETTINGS_MODULE = os.environ["DJANGO_SETTINGS_MODULE"]
  25
+    me.SETTINGS_MODULE = os.environ[ENVIRONMENT_VARIABLE]
  26
+    if not me.SETTINGS_MODULE: # If it's set but is an empty string.
  27
+        raise KeyError
24 28
 except KeyError:
25  
-    raise EnvironmentError, "Environment variable DJANGO_SETTINGS_MODULE is undefined."
  29
+    raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
26 30
 
27 31
 try:
28 32
     mod = __import__(me.SETTINGS_MODULE, '', '', [''])
29 33
 except ImportError, e:
30  
-    raise EnvironmentError, "Could not import DJANGO_SETTINGS_MODULE '%s' (is it on sys.path?): %s" % (me.SETTINGS_MODULE, e)
  34
+    raise EnvironmentError, "Could not import %s '%s' (is it on sys.path?): %s" % (ENVIRONMENT_VARIABLE, me.SETTINGS_MODULE, e)
31 35
 
32 36
 # Settings that should be converted into tuples if they're mistakenly entered
33 37
 # as strings.
@@ -41,7 +45,7 @@
41 45
         setattr(me, setting, setting_value)
42 46
 
43 47
 # save DJANGO_SETTINGS_MODULE in case anyone in the future cares
44  
-me.SETTINGS_MODULE = os.environ.get('DJANGO_SETTINGS_MODULE', '')
  48
+me.SETTINGS_MODULE = os.environ.get(ENVIRONMENT_VARIABLE, '')
45 49
 
46 50
 # move the time zone info into os.environ
47 51
 os.environ['TZ'] = me.TIME_ZONE
@@ -51,4 +55,3 @@
51 55
     if not k.startswith('_') and k != 'me' and k != k.upper():
52 56
         delattr(me, k)
53 57
 del me, k
54  
-

0 notes on commit 45c334d

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