diff --git a/example/templates/jinja2/index.jinja b/example/templates/jinja2/index.jinja
new file mode 100644
index 000000000..ffd1ada6f
--- /dev/null
+++ b/example/templates/jinja2/index.jinja
@@ -0,0 +1,12 @@
+
+
+
+
+ jinja Test
+
+
+
jinja Test
+ {{ foo }}
+ {% for i in range(10) %}{{ i }}{% endfor %} {# Jinja2 supports range(), Django templates do not #}
+
+
diff --git a/example/urls.py b/example/urls.py
index 6dded2da7..c5e60c309 100644
--- a/example/urls.py
+++ b/example/urls.py
@@ -3,7 +3,7 @@
from django.views.generic import TemplateView
from debug_toolbar.toolbar import debug_toolbar_urls
-from example.views import increment
+from example.views import increment, jinja2_view
urlpatterns = [
path("", TemplateView.as_view(template_name="index.html"), name="home"),
@@ -12,6 +12,7 @@
TemplateView.as_view(template_name="bad_form.html"),
name="bad_form",
),
+ path("jinja/", jinja2_view, name="jinja"),
path("jquery/", TemplateView.as_view(template_name="jquery/index.html")),
path("mootools/", TemplateView.as_view(template_name="mootools/index.html")),
path("prototype/", TemplateView.as_view(template_name="prototype/index.html")),
diff --git a/example/views.py b/example/views.py
index 46136515e..e7e4c1253 100644
--- a/example/views.py
+++ b/example/views.py
@@ -1,4 +1,5 @@
from django.http import JsonResponse
+from django.shortcuts import render
def increment(request):
@@ -8,3 +9,7 @@ def increment(request):
value = 1
request.session["value"] = value
return JsonResponse({"value": value})
+
+
+def jinja2_view(request):
+ return render(request, "index.jinja", {"foo": "bar"}, using="jinja2")
diff --git a/tests/panels/test_template.py b/tests/panels/test_template.py
index eb23cde31..2bd02bf1d 100644
--- a/tests/panels/test_template.py
+++ b/tests/panels/test_template.py
@@ -1,3 +1,5 @@
+from unittest import expectedFailure
+
import django
from django.contrib.auth.models import User
from django.template import Context, RequestContext, Template
@@ -135,11 +137,12 @@ def test_lazyobject_eval(self):
DEBUG=True, DEBUG_TOOLBAR_PANELS=["debug_toolbar.panels.templates.TemplatesPanel"]
)
class JinjaTemplateTestCase(IntegrationTestCase):
+ @expectedFailure
def test_django_jinja2(self):
r = self.client.get("/regular_jinja/foobar/")
self.assertContains(r, "Test for foobar (Jinja)")
self.assertContains(r, "
Templates (2 rendered)
")
- self.assertContains(r, "jinja2/basic.jinja")
+ self.assertContains(r, "basic.jinja")
def context_processor(request):
diff --git a/tests/templates/jinja2/base.html b/tests/templates/jinja2/base.html
new file mode 100644
index 000000000..ea0d773ac
--- /dev/null
+++ b/tests/templates/jinja2/base.html
@@ -0,0 +1,9 @@
+
+
+
+ {{ title }}
+
+
+ {% block content %}{% endblock %}
+
+
diff --git a/tests/templates/jinja2/basic.jinja b/tests/templates/jinja2/basic.jinja
index 812acbcac..e531eee64 100644
--- a/tests/templates/jinja2/basic.jinja
+++ b/tests/templates/jinja2/basic.jinja
@@ -1,2 +1,5 @@
{% extends 'base.html' %}
-{% block content %}Test for {{ title }} (Jinja){% endblock %}
+{% block content %}
+Test for {{ title }} (Jinja)
+{% for i in range(10) %}{{ i }}{% endfor %} {# Jinja2 supports range(), Django templates do not #}
+{% endblock %}
diff --git a/tests/views.py b/tests/views.py
index c7214029e..8ae4631fe 100644
--- a/tests/views.py
+++ b/tests/views.py
@@ -48,7 +48,7 @@ def json_view(request):
def regular_jinjia_view(request, title):
- return render(request, "jinja2/basic.jinja", {"title": title})
+ return render(request, "basic.jinja", {"title": title}, using="jinja2")
def listcomp_view(request):
From 4fd886bf91123e224f8f39e7abf4ff48a8ae5a35 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Thu, 4 Jul 2024 20:42:18 -0500
Subject: [PATCH 4/7] Improve the jinja tests to better indicate the situation.
---
tests/panels/test_template.py | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/tests/panels/test_template.py b/tests/panels/test_template.py
index 2bd02bf1d..636e88a23 100644
--- a/tests/panels/test_template.py
+++ b/tests/panels/test_template.py
@@ -137,8 +137,20 @@ def test_lazyobject_eval(self):
DEBUG=True, DEBUG_TOOLBAR_PANELS=["debug_toolbar.panels.templates.TemplatesPanel"]
)
class JinjaTemplateTestCase(IntegrationTestCase):
- @expectedFailure
def test_django_jinja2(self):
+ r = self.client.get("/regular_jinja/foobar/")
+ self.assertContains(r, "Test for foobar (Jinja)")
+ # This should be 2 templates because of the parent template.
+ # See test_django_jinja2_parent_template_instrumented
+ self.assertContains(r, "
Templates (1 rendered)
")
+ self.assertContains(r, "basic.jinja")
+
+ @expectedFailure
+ def test_django_jinja2_parent_template_instrumented(self):
+ """
+ When Jinja2 templates are properly instrumented, the
+ parent template should be instrumented.
+ """
r = self.client.get("/regular_jinja/foobar/")
self.assertContains(r, "Test for foobar (Jinja)")
self.assertContains(r, "
Templates (2 rendered)
")
From 661491059df0e0f2321bf71bafe58c2dccb672b6 Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Fri, 5 Jul 2024 06:28:31 -0500
Subject: [PATCH 5/7] Fix jinja2 integration test.
Now that we're using the actual jinja template backend,
it only instruments a single template.
---
tests/test_integration.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 71525affe..4899e7c0f 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -622,8 +622,9 @@ def test_basic_jinja(self):
# Click to show the template panel
self.selenium.find_element(By.CLASS_NAME, "TemplatesPanel").click()
-
- self.assertIn("Templates (2 rendered)", template_panel.text)
+ # This should be 2 templates rendered. See
+ # JinjaTemplateTestCase.test_django_jinja2_parent_template_instrumented
+ self.assertIn("Templates (1 rendered)", template_panel.text)
self.assertIn("base.html", template_panel.text)
self.assertIn("jinja2/basic.jinja", template_panel.text)
From 9834e7eed992055ff1408efb849ba38817ca3b5f Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Fri, 5 Jul 2024 06:40:11 -0500
Subject: [PATCH 6/7] Ignore check for jinja2's base.html template in
integration test
---
tests/test_integration.py | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tests/test_integration.py b/tests/test_integration.py
index 4899e7c0f..95207c21b 100644
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -622,10 +622,10 @@ def test_basic_jinja(self):
# Click to show the template panel
self.selenium.find_element(By.CLASS_NAME, "TemplatesPanel").click()
- # This should be 2 templates rendered. See
+ # This should be 2 templates rendered, including base.html See
# JinjaTemplateTestCase.test_django_jinja2_parent_template_instrumented
self.assertIn("Templates (1 rendered)", template_panel.text)
- self.assertIn("base.html", template_panel.text)
+ self.assertNotIn("base.html", template_panel.text)
self.assertIn("jinja2/basic.jinja", template_panel.text)
@override_settings(
From 57ada8e90c16d8973ca84c9e81b700ff0cb0d53c Mon Sep 17 00:00:00 2001
From: Tim Schilling
Date: Fri, 5 Jul 2024 06:16:51 -0500
Subject: [PATCH 7/7] Version 4.4.4
---
README.rst | 2 +-
debug_toolbar/__init__.py | 2 +-
docs/changes.rst | 3 +++
docs/conf.py | 2 +-
4 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/README.rst b/README.rst
index 2ce1db4b7..fa12e35c1 100644
--- a/README.rst
+++ b/README.rst
@@ -44,7 +44,7 @@ Here's a screenshot of the toolbar in action:
In addition to the built-in panels, a number of third-party panels are
contributed by the community.
-The current stable version of the Debug Toolbar is 4.4.3. It works on
+The current stable version of the Debug Toolbar is 4.4.4. It works on
Django ≥ 4.2.0.
The Debug Toolbar does not currently support `Django's asynchronous views
diff --git a/debug_toolbar/__init__.py b/debug_toolbar/__init__.py
index 5ddb15d15..f5f18057b 100644
--- a/debug_toolbar/__init__.py
+++ b/debug_toolbar/__init__.py
@@ -4,7 +4,7 @@
# Do not use pkg_resources to find the version but set it here directly!
# see issue #1446
-VERSION = "4.4.3"
+VERSION = "4.4.4"
# Code that discovers files or modules in INSTALLED_APPS imports this module.
urls = "debug_toolbar.urls", APP_NAME
diff --git a/docs/changes.rst b/docs/changes.rst
index 2ab16b544..539c9883c 100644
--- a/docs/changes.rst
+++ b/docs/changes.rst
@@ -4,6 +4,9 @@ Change log
Pending
-------
+4.4.4 (2024-07-05)
+------------------
+
* Added check for StreamingHttpResponse in alerts panel.
* Instrument the Django Jinja2 template backend. This only instruments
the immediate template that's rendered. It will not provide stats on
diff --git a/docs/conf.py b/docs/conf.py
index 5f69100f7..b155e44ef 100644
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -25,7 +25,7 @@
copyright = copyright.format(datetime.date.today().year)
# The full version, including alpha/beta/rc tags
-release = "4.4.3"
+release = "4.4.4"
# -- General configuration ---------------------------------------------------