From 66fa96306669364fd94e6974c545580b296c29df Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 4 May 2017 17:19:06 +0200 Subject: [PATCH 1/2] Refs #910: Skip template-based widget templates by default --- debug_toolbar/panels/templates/panel.py | 3 ++- debug_toolbar/settings.py | 5 +++++ docs/configuration.rst | 11 +++++++++++ docs/tips.rst | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index 1f96e97ee..b048cdb6c 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -85,7 +85,8 @@ def _store_template_info(self, sender, **kwargs): # Skip templates that we are generating through the debug toolbar. if (isinstance(template.name, six.string_types) and - template.name.startswith('debug_toolbar/')): + template.name.startswith( + tuple(self.toolbar.config['SKIP_TEMPLATE_PREFIXES']))): return context_list = [] diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index bfcc4022f..d45f7c8c0 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -35,6 +35,11 @@ ), 'PROFILER_MAX_DEPTH': 10, 'SHOW_TEMPLATE_CONTEXT': True, + 'SKIP_TEMPLATE_PREFIXES': ( + 'debug_toolbar/', + 'django/forms/widgets/', + 'admin/widgets', + ), 'SQL_WARNING_THRESHOLD': 500, # milliseconds } diff --git a/docs/configuration.rst b/docs/configuration.rst index efee40a13..a8cc95be1 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -170,6 +170,17 @@ Panel options template contexts, or you have template contexts with lazy datastructures that you don't want to be evaluated. +* ``SKIP_TEMPLATE_PREFIXES`` + + Default: ``('debug_toolbar/', 'django/forms/widgets/', 'admin/widgets/')`` + + Panel: templates. + + Templates starting with those strings are skipped when collecting + rendered templates and contexts. Template-based form widgets are + skipped by default because the panel HTML can easily grow to hundreds + of megabytes with many form fields and many options. + * ``SQL_WARNING_THRESHOLD`` Default: ``500`` diff --git a/docs/tips.rst b/docs/tips.rst index 78f28ca36..a4a18eb35 100644 --- a/docs/tips.rst +++ b/docs/tips.rst @@ -94,3 +94,6 @@ by disabling some configuration options that are enabled by default: - ``ENABLE_STACKTRACES`` for the SQL and cache panels, - ``SHOW_TEMPLATE_CONTEXT`` for the template panel. + +Also, check ``SKIP_TEMPLATE_PREFIXES`` when you're using template-based +form widgets. From a0ebcc3d2747465b11a135ede45782a9ad2b4863 Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Thu, 4 May 2017 21:41:42 +0200 Subject: [PATCH 2/2] Incorporate feedback --- debug_toolbar/panels/templates/panel.py | 7 ++++--- debug_toolbar/settings.py | 3 +-- docs/configuration.rst | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index b048cdb6c..7367cc153 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -84,9 +84,10 @@ def _store_template_info(self, sender, **kwargs): template, context = kwargs['template'], kwargs['context'] # Skip templates that we are generating through the debug toolbar. - if (isinstance(template.name, six.string_types) and - template.name.startswith( - tuple(self.toolbar.config['SKIP_TEMPLATE_PREFIXES']))): + if (isinstance(template.name, six.string_types) and ( + template.name.startswith('debug_toolbar/') or + template.name.startswith( + tuple(self.toolbar.config['SKIP_TEMPLATE_PREFIXES'])))): return context_list = [] diff --git a/debug_toolbar/settings.py b/debug_toolbar/settings.py index d45f7c8c0..dd7eda025 100644 --- a/debug_toolbar/settings.py +++ b/debug_toolbar/settings.py @@ -36,9 +36,8 @@ 'PROFILER_MAX_DEPTH': 10, 'SHOW_TEMPLATE_CONTEXT': True, 'SKIP_TEMPLATE_PREFIXES': ( - 'debug_toolbar/', 'django/forms/widgets/', - 'admin/widgets', + 'admin/widgets/', ), 'SQL_WARNING_THRESHOLD': 500, # milliseconds } diff --git a/docs/configuration.rst b/docs/configuration.rst index a8cc95be1..babc6ec79 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -172,7 +172,7 @@ Panel options * ``SKIP_TEMPLATE_PREFIXES`` - Default: ``('debug_toolbar/', 'django/forms/widgets/', 'admin/widgets/')`` + Default: ``('django/forms/widgets/', 'admin/widgets/')`` Panel: templates.