From 9cf0ac5b43b1a0ca4f838b0803325ce4f1940edc Mon Sep 17 00:00:00 2001 From: MyeongJun Go Date: Mon, 7 Oct 2019 22:33:49 +0900 Subject: [PATCH] fixed debugtool middleware be after GZip middleware (#12443) Fix django-debug-toolbar middleware be after GZip middleware --- settings.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/settings.py b/settings.py index 8a8e363270..517c6d4b99 100644 --- a/settings.py +++ b/settings.py @@ -19,7 +19,20 @@ INSTALLED_APPS += ( 'debug_toolbar', ) -MIDDLEWARE = ('debug_toolbar.middleware.DebugToolbarMiddleware',) + MIDDLEWARE +# django-debug-doolbar middleware needs to be inserted as high as possible +# but after GZip middleware +def insert_debug_toolbar_middleware(middlewares): + ret_middleware = list(middlewares) + + for i, middleware in enumerate(ret_middleware): + if 'GZipMiddleware' in middleware: + ret_middleware.insert( + i + 1, 'debug_toolbar.middleware.DebugToolbarMiddleware') + break + + return tuple(ret_middleware) + +MIDDLEWARE = insert_debug_toolbar_middleware(MIDDLEWARE) DEBUG_TOOLBAR_CONFIG = { # Enable django-debug-toolbar locally, if DEBUG is True.