summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdam Chainz <me@adamj.eu>2016-12-23 15:55:00 +0000
committerTim Graham <timograham@gmail.com>2016-12-23 10:55:00 -0500
commit8669cf0e684696971f6b577f5023634cb16f307e (patch)
treec57f1d5dc8ff02a6721222fb212cc6db223a6572 /django
parent8d94d575f821b16a25bfd9fcf739f2ee2febe2be (diff)
Fixed #27626 -- Moved MEDIA_URL/STATIC_URL validation to a system check.
Diffstat (limited to 'django')
-rw-r--r--django/conf/__init__.py14
-rw-r--r--django/core/checks/urls.py17
2 files changed, 19 insertions, 12 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index e9611aa3fe..4fec2ee646 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -74,17 +74,7 @@ class LazySettings(LazyObject):
return self._wrapped is not empty
-class BaseSettings(object):
- """
- Common logic for settings whether set by a module or by the user.
- """
- def __setattr__(self, name, value):
- if name in ("MEDIA_URL", "STATIC_URL") and value and not value.endswith('/'):
- raise ImproperlyConfigured("If set, %s must end with a slash" % name)
- object.__setattr__(self, name, value)
-
-
-class Settings(BaseSettings):
+class Settings(object):
def __init__(self, settings_module):
# update this dict from global settings (but only for ALL_CAPS settings)
for setting in dir(global_settings):
@@ -137,7 +127,7 @@ class Settings(BaseSettings):
}
-class UserSettingsHolder(BaseSettings):
+class UserSettingsHolder(object):
"""
Holder for user configured settings.
"""
diff --git a/django/core/checks/urls.py b/django/core/checks/urls.py
index 8187a4e561..e950cb5637 100644
--- a/django/core/checks/urls.py
+++ b/django/core/checks/urls.py
@@ -90,3 +90,20 @@ def get_warning_for_invalid_pattern(pattern):
hint=hint,
id="urls.E004",
)]
+
+
+@register(Tags.urls)
+def check_url_settings(app_configs, **kwargs):
+ errors = []
+ for name in ('STATIC_URL', 'MEDIA_URL'):
+ value = getattr(settings, name)
+ if value and not value.endswith('/'):
+ errors.append(E006(name))
+ return errors
+
+
+def E006(name):
+ return Error(
+ 'The {} setting must end with a slash.'.format(name),
+ id='urls.E006',
+ )