aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbkonkle2011-09-12 11:21:29 -0500
committerbkonkle2011-09-12 11:21:29 -0500
commitb77aec6160d66ee1ecff2687d74724ce74ea8ff5 (patch)
tree5b96e5d3d3390b493f76ece5f3ec08e793586aa4
parent7dfb666ae92ba2831926a003d26480a00a5dff30 (diff)
downloaddjango-debug-toolbar-b77aec6160d66ee1ecff2687d74724ce74ea8ff5.tar.bz2
Don't add the toolbar to the request object until the end of the process_response method
-rw-r--r--debug_toolbar/middleware.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/debug_toolbar/middleware.py b/debug_toolbar/middleware.py
index 1d332c0..b014f33 100644
--- a/debug_toolbar/middleware.py
+++ b/debug_toolbar/middleware.py
@@ -96,7 +96,6 @@ class DebugToolbarMiddleware(object):
for panel in toolbar.panels:
panel.process_request(request)
self.__class__.debug_toolbars[thread.get_ident()] = toolbar
- request.debug_toolbar = toolbar
def process_view(self, request, view_func, view_args, view_kwargs):
__traceback_hide__ = True
@@ -127,12 +126,15 @@ class DebugToolbarMiddleware(object):
response.get('Content-Type', '').split(';')[0] in _HTML_TYPES:
toolbar.stats = {}
for panel in toolbar.panels:
- panel.process_response(request, response)
+ panel.process_response(request, response)
response.content = replace_insensitive(
- smart_unicode(response.content),
- self.tag,
- smart_unicode(toolbar.render_toolbar() + self.tag))
+ smart_unicode(response.content),
+ self.tag,
+ smart_unicode(toolbar.render_toolbar() + self.tag))
if response.get('Content-Length', None):
response['Content-Length'] = len(response.content)
+ # Add the toolbar to the request object, so that the stats are
+ # available to subsequent middleware classes.
+ request.debug_toolbar = toolbar
del self.__class__.debug_toolbars[ident]
return response