码迷,mamicode.com
首页 > 其他好文 > 详细

Django(filter过滤器)

时间:2018-05-05 23:01:44      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:中间   .com   for   pre   cut   datetime   filter   add   files   

过滤器一般放在django中的html中

    {{ obj|upper }}                 #将obj大写                     hello  -> HELLO
    {{ obj|add:"2" }}               #在obj后边加上"2"               hello  -> hello2 
    {{ obj|cut:‘ ‘ }}               #将obj中间的空格减去             hel lo  wo r ld   ->helloworld
    {{ obj|date:‘Y-m-d‘ }}          #将obj以Y-m-d形式显示            datetime.datetime.now()  ->2018-06-05
    {{ obj|default:‘空的‘ }}         #如果obj只是定义没有赋值,那么默认给其赋值为"空的"     ""  ->空的
    {{ obj|safe }}                  #obj="<a href=‘#‘>跳转</a>",如果不加safe,渲染的就只是一个字符串,如果加上,渲染的就是一个连接 
{% autoescape off %} #同上safe作用 {{ obj }} {% endautoescape %}
htt {{ obj|filesizeformat }} {{ obj|urlencode }} 将obj编码 http://www.baidu.com/ ->http%3A//www.baidu.com

 

Django(filter过滤器)

标签:中间   .com   for   pre   cut   datetime   filter   add   files   

原文地址:https://www.cnblogs.com/gaoyukun/p/8996367.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!