Skip to content

Commit bbba2f8

Browse files
radwonmatthiask
authored andcommitted
Use the new STORAGES setting in Django 4.2
In Django 4.2 the django.core.files.storage.get_storage_class() function is deprecated as well as the STATICFILES_STORAGE setting in favor of STORAGES["staticfiles"]. Use django.core.files.storage.storages to get the configured storage class for static files instead. For Django versions prior to 4.2 keep using the django.core.files.storage.get_storage_class() function for backwards compatibility. Fixes #1758
1 parent 7b8a6cc commit bbba2f8

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

debug_toolbar/panels/staticfiles.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from django.conf import settings
44
from django.contrib.staticfiles import finders, storage
55
from django.core.checks import Warning
6-
from django.core.files.storage import get_storage_class
76
from django.utils.functional import LazyObject
87
from django.utils.translation import gettext_lazy as _, ngettext
98

@@ -53,7 +52,17 @@ class DebugConfiguredStorage(LazyObject):
5352
"""
5453

5554
def _setup(self):
56-
configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)
55+
try:
56+
# From Django 4.2 use django.core.files.storage.storages in favor
57+
# of the deprecated django.core.files.storage.get_storage_class
58+
from django.core.files.storage import storages
59+
60+
configured_storage_cls = storages["staticfiles"].__class__
61+
except ImportError:
62+
# Backwards compatibility for Django versions prior to 4.2
63+
from django.core.files.storage import get_storage_class
64+
65+
configured_storage_cls = get_storage_class(settings.STATICFILES_STORAGE)
5766

5867
class DebugStaticFilesStorage(configured_storage_cls):
5968
def __init__(self, collector, *args, **kwargs):

0 commit comments

Comments
 (0)