Python Django模板標籤php
1、if、for標籤html
# cat blog/views.pyjava
from django.shortcuts import render_to_responsepython
def index(req):web
user = {'name':'loyu','age':23,'sex':'male'}django
book_list = ['python','java','php','web']ide
return render_to_response('index.html',{'title':'Loyu page','user':user,'book_list':book_list})oop
# cat blog/template/index.htmlui
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">spa
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<title>`title`</title>
</head>
<body>
{% if user %}
<li>name:`user`.`name`</li>
{% else %}
用戶不存在
{% endif %}
{% for book in book_list %}
<li>`book`</li>
{% endfor %}
{% for k,v in user.items %}
<li>`forloop`.`counter`.`k`:`v`</li>
{% endfor %}
</body>
</html>