Django 中 过滤器大全

# django中过滤器的使用
1. name | lower 小写
2. value | upper 大写
3. text | escape | linebreaks 转化为块标签
4. bio | teuncatewords : 30 截取前30个单词
5. list | join:"," 连接符号
6. value | default :”nothing“ 默认值
7. value | length 返回字符窜或者列表值得长度
8. value | filesizeformat 转化为人类可读方式 如 “13 KB” , “4.1 MB” '102 bytes', etc.
9. value | add : "2" 加法过滤器 , 数值 数组
10.vlaue | capfirst 对单词首字母进行大写
11.value | addslashes 对特殊字符进行转义 “ I \ 'm using Django” .
12.value | center : "15" 将单词进行居中
13.value | cut :" " 过滤掉输出之中的空格
14.value | date : “D d M Y ” 输出指定的日期格式, 更多参数查看官网文档
15.{{ value | date:"D d M Y" }} {{ value | time:"H:i" }}
16.value | default_if_none:"nothing" if value is None, the output will be nothing.
17.value | dictsort : "name" 按照name进行排序 {% for book in books | dictsort:"author.age" %}
18.value | dictsort:0 指定列表的索引进行排序
19.dictsortreversed 过滤是倒叙的
20.value | divisibleby:"3" 前面的值能够别3整除,就返回true
21.title | escape 避免一些特殊字符转化为html
22.value | first 输出列表中的首个元素
23.value | first 输出列表中的首个元素
24.value | floatformat 四舍五入保留2位小数
25.value | floatformat:3 指定保留3位小数
26.value | floatformat:3 指定保留3位小数
27.value | floatformat:"0" 保留整数
28.body | linebreaks|force_escape 已linebreaks生成p标签,为了避免再次被html化,使用该标签过滤
29.value | get_digit:"2" 返回右边索引为2的数字
30.value | iriencode 转化url
31.value | join:" // " 链接付 值之间的 如列表数组
32.value | json_script:"hello-data" 添加script标签 如果value is the dictionary {'hello': 'world'}, 也就能在前端进行抓取与获取了 var value = JSON.parse(document.getElementById('hello-data').textContent); 注意这个里面不能使用特殊字符,严文本格式
33.value | last 显示列表的最后一个元素
34.value | length_is:"4" 判断元素的长度是否为4 返回true
35.value | linenumbers 显示行号
36.value | ljust:"10" 右边留10个字符
37.value | phone2numeric 转化为电话号码格式
38.num_messages | pluralize 根据数量转化为偶数,加个s
39.num_walruses | pluralize:"es" 指定后缀 num_cherries | pluralize:"y,ies"
40.value | random 给出随机数 列表
41.value | rjust:"10" 左边空10个数值
42.some_list | slice:":2" 切片
43.value | slugify slug化 Joel is a slug", the output will be "joel-is-a-slug".
44.value | wordcount 计算有几个单词 注意 不是字母
45.value | urlizetrunc:15 转化URLs and email addresses into clickable links
46.value | urlize
47.value | urlencode:"" 将url中的特殊字符进行转码
48.value | urlencode unordered_list 将列表转化为无序列表 就是展示ul li标签
49.value | truncatewords_html:2 标签内单词进行截断 并添加..
50.value | title 转化为标题
51.conference_date | timeuntil:from_date 返回周数 从给定日期减去当前日期还剩n周 返回
52.blog_date | timesince:comment_date 返回小时
53.value | time:"TIME_FORMAT"
54.value | time
55.value | time:"H:i"
56.value | striptags :If value is "Joel a slug", the output will be "Joel is a slug".
57.value | stringformat:"E":if value is 10, the output will be 1.000000E+01.
58.var | safe | escape 关闭html转义
59.some_list | safeseq | join:", "
posted @ 2021-04-19 11:07  石宏建  阅读(317)  评论(0编辑  收藏  举报