Skip to content

Commit

Permalink
Only import the jinja2 instrumentation when jinja2 itself is importab…
Browse files Browse the repository at this point in the history
…le (#1954)

Closes #1949.
  • Loading branch information
matthiask authored Jul 5, 2024
1 parent a591d86 commit 944120c
Showing 1 changed file with 6 additions and 3 deletions.
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 comments on commit 944120c

Please sign in to comment.