File tree Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Expand file tree Collapse file tree 2 files changed +6
-5
lines changed Original file line number Diff line number Diff line change 1+ import django
2+
13try :
24 from django .contrib .auth .decorators import login_not_required
35except 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
Original file line number Diff line number Diff line change 11from __future__ import annotations
22
3- from importlib .util import find_spec
4-
3+ import django
54from django .conf import settings
65from django .test .utils import override_settings
76from html5lib .constants import E
2221
2322VALID_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 )
2625if django_has_builtin_csp_support :
2726 MIDDLEWARE_CSP_BUILTIN_BEFORE = settings .MIDDLEWARE .copy ()
2827 MIDDLEWARE_CSP_BUILTIN_BEFORE .insert (
You can’t perform that action at this time.
0 commit comments