Skip to content

Refs #910: Skip template-based widget templates by default #942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +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('debug_toolbar/')):
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 = []
Expand Down
4 changes: 4 additions & 0 deletions debug_toolbar/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
),
'PROFILER_MAX_DEPTH': 10,
'SHOW_TEMPLATE_CONTEXT': True,
'SKIP_TEMPLATE_PREFIXES': (
'django/forms/widgets/',
'admin/widgets/',
),
'SQL_WARNING_THRESHOLD': 500, # milliseconds
}

Expand Down
11 changes: 11 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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: ``('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``
Expand Down
3 changes: 3 additions & 0 deletions docs/tips.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.