Django模板练习代码

exercise.html

1
2
3
4
5
6
7
8
9
10
11
12
<html>
<body>
<table>
{% for k,v in values %}
<tr>
<td>{{k}}</td>
<td>{{v}}</td>
</tr>
{% endfor %}
</table>
</body>
</html>

view.py

1
2
3
4
5
6
7
def display_ex(request):
values = request.META.items()
values.sort()
t = get_template('exercise.html')
c = Context({'values':values})
html = t.render(c)
return HttpResponse(html)

热评文章