当前位置: 首页 > 图灵资讯 > 行业资讯> python常见过滤器的整理

python常见过滤器的整理

发布时间:2024-07-25 20:29:48

常见过滤器

1、safe渲染值不转义。

2、capitialize将值的首字母转换为大写,其他子母转换为小写。

3、lower将值转换为小写。

4、upper将值转换为大写形式。

另外还有:

title: 将值中每个单词的首字母转换为大写

trim: 去掉值的第一尾空间

striptags: 在渲染之前,删除值中所有的HTML标签

join: 拼接多个值为字符串

replace: 替换字符串的值

round: 默认情况下,数字可以四舍五入,也可以用参数控制

int: 将值转换为整形手术

实例

{{'abc'|captialize}
#Abc

{{'abc'|upper}
#ABC

{{'helloworld'|title}
#HelloWorld

{{"helloworld"|replace('world','daxin')|upper}
#HELLODAXIN

{{18.18|round|int}
#18

以上是python常见过滤器的整理,希望对大家有所帮助。更多Python学习指导:python基础教程

本文教程操作环境:windows7系统Python 3.9.1,DELL G3电脑。

相关文章

python3兼容python2吗

python3兼容python2吗

2025-05-09
python3 whl怎么安装

python3 whl怎么安装

2025-05-09
python 字典怎么提取value

python 字典怎么提取value

2025-05-09
python 怎样计算字符串的长度

python 怎样计算字符串的长度

2025-05-09
python 怎么样反向输出字符串

python 怎么样反向输出字符串

2025-05-09
python 怎么判断字符串开头

python 怎么判断字符串开头

2025-05-09