diff options
| author | Florian Apolloner <apollo13@users.noreply.github.com> | 2020-07-28 12:52:28 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-07-28 12:52:28 +0200 |
| commit | 7dbbe65647a54283fadf2c51f11a750a74425d7b (patch) | |
| tree | 3e5fb9410cc2c89ff4c802260dd8446b7b2e128a /django/conf | |
| parent | bac5777bff8e8d8189193438b5af52f158a3f2a4 (diff) | |
Improved performance of STATIC_URL and MEDIA_URL setting access.
Run `add_script_prefix()` on first access, rather than on every time.
Diffstat (limited to 'django/conf')
| -rw-r--r-- | django/conf/__init__.py | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index ec7efadf46..3bfd8ea4a1 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -76,6 +76,12 @@ class LazySettings(LazyObject): if self._wrapped is empty: self._setup(name) val = getattr(self._wrapped, name) + + # Special case some settings which require further modification. + # This is done here for performance reasons so the modified value is cached. + if name in {'MEDIA_URL', 'STATIC_URL'} and val is not None: + val = self._add_script_prefix(val) + self.__dict__[name] = val return val @@ -149,14 +155,6 @@ class LazySettings(LazyObject): ) return self.__getattr__('PASSWORD_RESET_TIMEOUT_DAYS') - @property - def STATIC_URL(self): - return self._add_script_prefix(self.__getattr__('STATIC_URL')) - - @property - def MEDIA_URL(self): - return self._add_script_prefix(self.__getattr__('MEDIA_URL')) - class Settings: def __init__(self, settings_module): |
