Python Django Template Tags
First, if, for label
# Cat blog/views.py
From django.shortcuts import Render_to_response
def index (req):
user = {' name ': ' Loyu ', ' age ': $, ' sex ': ' Male '}
Book_list = [' Python ', ' java ', ' php ', ' web ']
Return Render_to_response (' index.html ', {' title ': ' Loyu page ', ' user ': User, ' Book_list ': book_list})
# Cat Blog/template/index.html
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8"/>
<title>{{title}}</title>
<body>
{% if user%}
<li>name:{{user.name}}</li>
{% Else%}
User does not exist
{% ENDIF%}
{% for book in book_list%}
<li>{{book}}</li>
{% ENDFOR%}
{% for k,v in user.items%}
<li>{{forloop.counter}}. {{k}}:{{v}}</li>
{% ENDFOR%}
</body>
This article is from "Meteor Yu" blog, please be sure to keep this source http://8789878.blog.51cto.com/8779878/1850743
V. Python template tags for Django