@@ -21,7 +21,7 @@ def check_middleware(app_configs, **kwargs):
21
21
22
22
errors = []
23
23
gzip_index = None
24
- debug_toolbar_index = None
24
+ debug_toolbar_indexes = []
25
25
26
26
setting = getattr (settings , 'MIDDLEWARE' , None )
27
27
setting_name = 'MIDDLEWARE'
@@ -34,9 +34,9 @@ def check_middleware(app_configs, **kwargs):
34
34
if is_middleware_class (GZipMiddleware , middleware ):
35
35
gzip_index = i
36
36
elif is_middleware_class (DebugToolbarMiddleware , middleware ):
37
- debug_toolbar_index = i
37
+ debug_toolbar_indexes . append ( i )
38
38
39
- if debug_toolbar_index is None :
39
+ if not debug_toolbar_indexes :
40
40
# If the toolbar does not appear, report an error.
41
41
errors .append (
42
42
Error (
@@ -46,7 +46,16 @@ def check_middleware(app_configs, **kwargs):
46
46
"%s." % setting_name ,
47
47
)
48
48
)
49
- elif gzip_index is not None and debug_toolbar_index < gzip_index :
49
+ elif len (debug_toolbar_indexes ) != 1 :
50
+ errors .append (
51
+ Error (
52
+ "debug_toolbar.middleware.DebugToolbarMiddleware occurs "
53
+ "multiple times in %s." % setting_name ,
54
+ hint = "Load debug_toolbar.middleware.DebugToolbarMiddleware only "
55
+ "once in %s." % setting_name ,
56
+ )
57
+ )
58
+ elif gzip_index is not None and debug_toolbar_indexes [0 ] < gzip_index :
50
59
# If the toolbar appears before the gzip index, report an error.
51
60
errors .append (
52
61
Error (
0 commit comments