您的位置:首页 > 编程语言 > Go语言

django的模版标签和过滤器

2016-04-09 20:54 369 查看
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'}))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  django