Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
Showing with 8 additions and 5 deletions.
  1. +8 −5 django/conf/settings.py
View
13 django/conf/settings.py
@@ -10,6 +10,8 @@
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 @@
# 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 @@
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 @@
if not k.startswith('_') and k != 'me' and k != k.upper():
delattr(me, k)
del me, k
-
Please sign in to comment.
Something went wrong with that request. Please try again.