From 89a0b38316e1822bf22a4f013a6bb12f9db585b8 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 11 Aug 2009 13:33:03 -0500 Subject: allow for handling the pathological case of an insanely large template context --- README.rst | 5 +++++ debug_toolbar/panels/template.py | 19 ++++++++++--------- .../templates/debug_toolbar/panels/templates.html | 10 ++++++---- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 60aa8d0..79b224a 100644 --- a/README.rst +++ b/README.rst @@ -104,6 +104,11 @@ The debug toolbar has two settings that can be set in `settings.py`: * `HIDE_DJANGO_SQL`: If set to True (the default) then code in Django itself won't be show in SQL stacktraces. + * `SHOW_TEMPLATE_CONTEXT`: If set to True (the default) then a template's + context will be included with it in the Template debug panel. Turning this + off is useful when you have large template contexts, or you have template + contexts with lazy datastructures that you don't want to be evaluated. + Example configuration:: def custom_show_toolbar(request): diff --git a/debug_toolbar/panels/template.py b/debug_toolbar/panels/template.py index ad6dd04..e99b9c5 100644 --- a/debug_toolbar/panels/template.py +++ b/debug_toolbar/panels/template.py @@ -73,15 +73,16 @@ class TemplateDebugPanel(DebugPanel): t.origin_name = 'No origin' info['template'] = t # Clean up context for better readability - c = d.get('context', None) - - d_list = [] - for _d in c.dicts: - try: - d_list.append(pformat(d)) - except UnicodeEncodeError: - pass - info['context'] = '\n'.join(d_list) + if getattr(settings, 'DEBUG_TOOLBAR_CONFIG', {}).get('SHOW_TEMPLATE_CONTEXT', True): + c = d.get('context', None) + + d_list = [] + for _d in c.dicts: + try: + d_list.append(pformat(d)) + except UnicodeEncodeError: + pass + info['context'] = '\n'.join(d_list) template_context.append(info) context = { 'templates': template_context, diff --git a/debug_toolbar/templates/debug_toolbar/panels/templates.html b/debug_toolbar/templates/debug_toolbar/panels/templates.html index 6c918b1..e54c951 100644 --- a/debug_toolbar/templates/debug_toolbar/panels/templates.html +++ b/debug_toolbar/templates/debug_toolbar/panels/templates.html @@ -14,10 +14,12 @@ {% for template in templates %}
{{ template.template.name|addslashes }}
{{ template.template.origin_name|addslashes }}
-
-
Toggle Context
- -
+ {% if template.context %} +
+
Toggle Context
+ +
+ {% endif %} {% endfor %} {% else %} -- cgit v1.2.3