Skip to content

Commit 75ce3c9

Browse files
committed
Base feature detection on django.VERSION
1 parent 0920a11 commit 75ce3c9

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

debug_toolbar/_compat.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import django
2+
13
try:
24
from django.contrib.auth.decorators import login_not_required
35
except ImportError:
@@ -10,9 +12,9 @@ def login_not_required(view_func):
1012
return view_func
1113

1214

13-
try:
15+
if django.VERSION >= (6, 0):
1416
from django.middleware.csp import get_nonce
15-
except ImportError:
17+
else:
1618
# For Django < 6.0, there is no native CSP support, hence no CSP nonces.
1719
def get_nonce(request):
1820
return None

tests/test_csp_rendering.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

3-
from importlib.util import find_spec
4-
3+
import django
54
from django.conf import settings
65
from django.test.utils import override_settings
76
from html5lib.constants import E
@@ -22,7 +21,7 @@
2221

2322
VALID_MIDDLEWARE_VARIATIONS = [MIDDLEWARE_CSP_LIB_BEFORE, MIDDLEWARE_CSP_LIB_LAST]
2423

25-
django_has_builtin_csp_support = bool(find_spec("django.middleware.csp"))
24+
django_has_builtin_csp_support = django.VERSION >= (6, 0)
2625
if django_has_builtin_csp_support:
2726
MIDDLEWARE_CSP_BUILTIN_BEFORE = settings.MIDDLEWARE.copy()
2827
MIDDLEWARE_CSP_BUILTIN_BEFORE.insert(

0 commit comments

Comments
 (0)