Skip to content

Commit 39e2e77

Browse files
committed
Switch to the render function so we can include context.
1 parent d49a2d0 commit 39e2e77

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

example/templates/jinja2/index.jinja

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
</head>
77
<body>
88
<h1>jinja Test</h1>
9+
{{ foo }}
910
{% for i in range(10) %}{{ i }}{% endfor %} {# Jinja2 supports range(), Django templates do not #}
1011
</body>
1112
</html>

example/urls.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22
from django.urls import include, path
33
from django.views.generic import TemplateView
44

5-
from example.views import increment
5+
from example.views import increment, jinja2_view
66

77
urlpatterns = [
88
path("", TemplateView.as_view(template_name="index.html"), name="home"),
9-
path(
10-
"jinja/",
11-
TemplateView.as_view(template_name="index.jinja", template_engine="jinja2"),
12-
),
9+
path("jinja/", jinja2_view),
1310
path("jquery/", TemplateView.as_view(template_name="jquery/index.html")),
1411
path("mootools/", TemplateView.as_view(template_name="mootools/index.html")),
1512
path("prototype/", TemplateView.as_view(template_name="prototype/index.html")),

example/views.py

+5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.http import JsonResponse
2+
from django.shortcuts import render
23

34

45
def increment(request):
@@ -8,3 +9,7 @@ def increment(request):
89
value = 1
910
request.session["value"] = value
1011
return JsonResponse({"value": value})
12+
13+
14+
def jinja2_view(request):
15+
return render(request, "index.jinja", {"foo": "bar"}, using="jinja2")

0 commit comments

Comments
 (0)