@@ -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,17 @@ 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
+ # If the toolbar appears multiple times, report an error.
51
+ errors .append (
52
+ Error (
53
+ "debug_toolbar.middleware.DebugToolbarMiddleware occurs "
54
+ "multiple times in %s." % setting_name ,
55
+ hint = "Load debug_toolbar.middleware.DebugToolbarMiddleware only "
56
+ "once in %s." % setting_name ,
57
+ )
58
+ )
59
+ elif gzip_index is not None and debug_toolbar_indexes [0 ] < gzip_index :
50
60
# If the toolbar appears before the gzip index, report an error.
51
61
errors .append (
52
62
Error (
0 commit comments