diff --git a/debug_toolbar/panels/templates/panel.py b/debug_toolbar/panels/templates/panel.py index 182f80aab..ee2a066c7 100644 --- a/debug_toolbar/panels/templates/panel.py +++ b/debug_toolbar/panels/templates/panel.py @@ -1,4 +1,5 @@ from contextlib import contextmanager +from importlib.util import find_spec from os.path import normpath from pprint import pformat, saferepr @@ -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. @@ -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.