8000 Only import the jinja2 instrumentation when jinja2 itself is importable by matthiask · Pull Request #1954 · django-commons/django-debug-toolbar · GitHub
[go: up one dir, main page]

Skip to content

Only import the jinja2 instrumentation when jinja2 itself is importable #1954

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 1 commit into from
Jul 5, 2024
Merged
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
9 changes: 6 additions & 3 deletions debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from contextlib import contextmanager
from importlib.util import find_spec
from os.path import normpath
from pprint import pformat, saferepr

Expand All @@ -14,7 +15,11 @@
from debug_toolbar.panels import Panel
from debug_toolbar.panels.sql.tracking import SQLQueryTriggered, allow_sql
from debug_toolbar.panels.templates import views
from debug_toolbar.panels.templates.jinja2 import patch_jinja_render

if find_spec("jinja2"):
from debug_toolbar.panels.templates.jinja2 import patch_jinja_render

patch_jinja_render()

# Monkey-patch to enable the template_rendered signal. The receiver returns
# immediately when the panel is disabled to keep the overhead small.
Expand All @@ -26,8 +31,6 @@
Template.original_render = Template._render
Template._render = instrumented_test_render

patch_jinja_render()

# Monkey-patch to store items added by template context processors. The
# overhead is sufficiently small to justify enabling it unconditionally.

Expand Down
0