高安全性的内容管理系统
一站式建站解决方案
高性能静态网站构建工具
精美的网站模板库
详细的模板开发指南
完整的API接口说明
直观的视频使用指南
常见问题解答集锦
最新产品动态与行业资讯
了解我们的故事
获取支持与合作
center 过滤器可以将字符串按指定长度格式居中显示。如果字符串长度大于指定的长度,则按字符串实际长度显示,如果字符串长度小于指定的长度,则会在字符串两边补充同等数量的空格来实现居中。如果需要补充的空格数量为单数,则分配右边的空格会比左边少一个。
center
ljust 过滤器可以将字符串按指定长度格式靠左显示。如果字符串长度大于指定的长度,则按字符串实际长度显示,如果字符串长度小于指定的长度,则会在字符串右边补充空格。。
ljust
rjust 过滤器可以将字符串按指定长度格式靠右显示。如果字符串长度大于指定的长度,则按字符串实际长度显示,如果字符串长度小于指定的长度,则会在字符串左边补充空格。
rjust
center 过滤器的使用方法:
{{ obj|center:number }}
ljust 过滤器的使用方法:
{{ obj|ljust:number }}
rjust 过滤器的使用方法:
{{ obj|rjust:number }}
比如将 test 按 20 个字符长度居中显示,则可以这么写:
test
'{{ "test"|center:20 }}' # 显示结果 ' test '
center 过滤器
'{{ "test"|center:3 }}' '{{ "test"|center:19 }}' '{{ "test"|center:20 }}' {{ "test"|center:20|length }} '{{ "test2"|center:19 }}' '{{ "test2"|center:20 }}' {{ "test2"|center:20|length }} '{{ "你好世界"|center:20 }}' # 显示结果 'test' ' test ' ' test ' 20 ' test2 ' ' test2 ' 20 ' 你好世界 '
ljust 过滤器
'{{ "test"|ljust:"2" }}' '{{ "test"|ljust:"20" }}' {{ "test"|ljust:"20"|length }} '{{ "你好世界"|ljust:10 }}' # 显示结果 'test' 'test ' 20 '你好世界 '
rjust 过滤器
'{{ "test"|rjust:"2" }}' '{{ "test"|rjust:"20" }}' {{ "test"|rjust:"20"|length }} '{{ "你好世界"|rjust:10 }}' # 显示结果 'test' ' test' 20 ' 你好世界'