summaryrefslogtreecommitdiff
path: root/django/conf/__init__.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2018-04-13 13:18:53 -0700
committerTim Graham <timograham@gmail.com>2018-04-17 13:02:05 -0400
commitb3cffde5559c4fa97625512d7ec41a674be26076 (patch)
treeb5ad741522c6ffab550c1d98fa8200d6eb5abd6b /django/conf/__init__.py
parentfff689ed982c9aeb1402446c4eb91c2fb5a2c832 (diff)
downloaddjango-b3cffde5559c4fa97625512d7ec41a674be26076.tar.gz
Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is accessed and not set.
Diffstat (limited to 'django/conf/__init__.py')
-rw-r--r--django/conf/__init__.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index 9e4b0a4b1e..6813afb3b8 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -115,15 +115,15 @@ class Settings:
if setting.isupper():
setting_value = getattr(mod, setting)
+ if setting == 'SECRET_KEY' and not setting_value:
+ raise ImproperlyConfigured('The SECRET_KEY setting must not be empty.')
+
if (setting in tuple_settings and
not isinstance(setting_value, (list, tuple))):
raise ImproperlyConfigured("The %s setting must be a list or a tuple. " % setting)
setattr(self, setting, setting_value)
self._explicit_settings.add(setting)
- if not self.SECRET_KEY:
- raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
-
if self.is_overridden('DEFAULT_CONTENT_TYPE'):
warnings.warn('The DEFAULT_CONTENT_TYPE setting is deprecated.', RemovedInDjango30Warning)
@@ -139,6 +139,11 @@ class Settings:
os.environ['TZ'] = self.TIME_ZONE
time.tzset()
+ def __getattr__(self, name):
+ if name == 'SECRET_KEY':
+ raise ImproperlyConfigured('The SECRET_KEY setting must be set.')
+ raise AttributeError("'%s' object has no attribute '%s'" % (self.__class__.__name__, name))
+
def is_overridden(self, setting):
return setting in self._explicit_settings