Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed #5743 -- Tweaked the exceptions raised when importing settings …

…so that we

cooperate with Python's standard help() function. Patch from ionut_bizau and
Ben Slavin.

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 49da9ab commit 81832f594d7b0d3b671bf12878a77f7a34fb2f04 @malcolmt malcolmt committed
6 django/conf/
@@ -52,7 +52,7 @@ def _import_settings(self):
if not settings_module: # If it's set but is an empty string.
raise KeyError
except KeyError:
- raise EnvironmentError, "Environment variable %s is undefined." % ENVIRONMENT_VARIABLE
+ raise ImportError, "Environment variable %s is undefined so settings cannot be imported." % ENVIRONMENT_VARIABLE # NOTE: This is arguably an EnvironmentError, but that causes problems with Python's interactive help
self._target = Settings(settings_module)
@@ -63,7 +63,7 @@ def configure(self, default_settings=global_settings, **options):
argument must support attribute access (__getattr__)).
if self._target != None:
- raise EnvironmentError, 'Settings already configured.'
+ raise RuntimeError, 'Settings already configured.'
holder = UserSettingsHolder(default_settings)
for name, value in options.items():
setattr(holder, name, value)
@@ -82,7 +82,7 @@ def __init__(self, settings_module):
mod = __import__(self.SETTINGS_MODULE, {}, {}, [''])
except ImportError, e:
- raise EnvironmentError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
+ raise ImportError, "Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e)
# Settings that should be converted into tuples if they're mistakenly entered
# as strings.
4 django/core/management/
@@ -84,7 +84,7 @@ def get_commands():
from django.conf import settings
apps = settings.INSTALLED_APPS
- except (AttributeError, EnvironmentError):
+ except (AttributeError, ImportError):
apps = []
for app_name in apps:
@@ -99,7 +99,7 @@ def get_commands():
from django.conf import settings
project_directory = setup_environ(__import__(settings.SETTINGS_MODULE))
- except (AttributeError, EnvironmentError, ImportError):
+ except (AttributeError, ImportError):
project_directory = None
if project_directory:
2  django/newforms/
@@ -409,7 +409,7 @@ def __init__(self, max_length=None, min_length=None, *args, **kwargs):
from django.conf import settings
-except (ImportError, EnvironmentError):
+except ImportError:
# It's OK if Django settings aren't configured.
6 docs/settings.txt
@@ -1166,12 +1166,12 @@ If you're not setting the ``DJANGO_SETTINGS_MODULE`` environment variable, you
If you don't set ``DJANGO_SETTINGS_MODULE`` and don't call ``configure()``,
-Django will raise an ``EnvironmentError`` exception the first time a setting
+Django will raise an ``ImportError`` exception the first time a setting
is accessed.
If you set ``DJANGO_SETTINGS_MODULE``, access settings values somehow, *then*
-call ``configure()``, Django will raise an ``EnvironmentError`` saying settings
-have already been configured.
+call ``configure()``, Django will raise a ``RuntimeError`` indicating
+that settings have already been configured.
Also, it's an error to call ``configure()`` more than once, or to call
``configure()`` after any setting has been accessed.

0 comments on commit 81832f5

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