Skip to content

Commit a8d5563

Browse files
committed
Write a view using Jinaja2 templating engine
1 parent e7a9ed0 commit a8d5563

File tree

6 files changed

+16
-1
lines changed

6 files changed

+16
-1
lines changed

requirements_dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
Django
88
sqlparse
9+
Jinja2
910

1011
# Testing
1112

tests/panels/test_redirects.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def test_redirect(self):
3838

3939
def test_redirect_with_broken_context_processor(self):
4040
TEMPLATES = copy.deepcopy(settings.TEMPLATES)
41-
TEMPLATES[0]['OPTIONS']['context_processors'] = ['tests.context_processors.broken']
41+
TEMPLATES[1]['OPTIONS']['context_processors'] = ['tests.context_processors.broken']
4242

4343
with self.settings(TEMPLATES=TEMPLATES):
4444
redirect = HttpResponse(status=302)

tests/settings.py

+6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
ROOT_URLCONF = 'tests.urls'
4444

4545
TEMPLATES = [
46+
{
47+
'NAME': 'jinja2',
48+
'BACKEND': 'django_jinja.backend.Jinja2',
49+
'APP_DIRS': True,
50+
'DIRS': [os.path.join(BASE_DIR, 'tests', 'templates', 'jinja2')],
51+
},
4652
{
4753
'BACKEND': 'django.template.backends.django.DjangoTemplates',
4854
'APP_DIRS': True,

tests/templates/jinja2/basic.jinja

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{% extends "base.html" %}
2+
{% block content %}Test for {{ title }} (Jinja){% endblock %}
3+

tests/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
url(r'^resolving2/(?P<arg1>.+)/(?P<arg2>.+)/$', views.resolving_view),
1515
url(r'^resolving3/(.+)/$', views.resolving_view, {'arg2': 'default'}),
1616
url(r'^regular/(?P<title>.*)/$', views.regular_view),
17+
url(r'^regular_jinja/(?P<title>.*)/$', views.regular_jinjia_view),
1718
url(r'^non_ascii_request/$', views.regular_view, {'title': NonAsciiRepr()}),
1819
url(r'^new_user/$', views.new_user),
1920
url(r'^execute_sql/$', views.execute_sql),

tests/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ def resolving_view(request, arg1, arg2):
3030
@cache_page(60)
3131
def cached_view(request):
3232
return HttpResponse()
33+
34+
35+
def regular_jinjia_view(request, title):
36+
return render(request, 'jinja2/basic.jinja', {'title': title})

0 commit comments

Comments
 (0)