python manage.py shell
from django import template
if标签的使用
t = template.Template(‘{%if a%}A is true{%else%}A is False{%endif%}')
t.render(template.Context({‘a’:True}))
for标签的使用
t = template.Template('{%for i in items%}<li>{{i}}</li>{%endfor%}')
t.render(template.Context({‘items’:[1,3,4,5,6,6]}))
过滤器的使用:
t = template.Template(‘{{a|lower]}’).render(template.Context({‘a’:’CCCAB'}))
t = template.Template(‘{{a|upper]}’).render(template.Context({‘a’:’CCCAB'}))
t = template.Template(‘{{a|first]}’).render(template.Context({‘a’:’CCCAB'}))
t = template.Template(‘{{a|last]}’).render(template.Context({‘a’:’CCCAB'}))
t = template.Template(‘{{a|truncatechars:3]}’).render(template.Context({‘a’:’CCCAB'}))
t = template.Template(‘{{a|truncatewords]}’).render(template.Context({‘a’:’CCCAB'}))