高安全性的内容管理系统
一站式建站解决方案
高性能静态网站构建工具
精美的网站模板库
详细的模板开发指南
完整的API接口说明
直观的视频使用指南
常见问题解答集锦
最新产品动态与行业资讯
了解我们的故事
获取支持与合作
linebreaks 过滤器可以将多行文本按换行符转换成 html 标签。每行开头和结尾采用<p>和</p>包裹,中间有空行则采用 <br/>。
linebreaks
<p>
</p>
<br/>
还可以使用 linebreaksbr 来进行处理。与 linebreaks不同的地方是,linebreaksbr只是直接将换行符替换成 <br/>,并且不在开头和结尾添加 p 标签。
linebreaksbr
还可以使用 linenumbers 来给多行文本的每一行进行标号,符号从 1 开始。如 1.。
linenumbers
1.
linebreaks 过滤器的使用方法:
{{ obj|linebreaks }}
linebreaksbr 过滤器的使用方法:
{{ obj|linebreaksbr }}
linenumbers 过滤器的使用方法:
{{ obj|linenumbers }}
比如处理字符串 this is a text\nwith a new line in it,则可以这么写:
this is a text\nwith a new line in it
{{ "this is a text\nwith a new line in it"|linebreaks }} # 显示结果 <p>this is a text<br />with a new line in it</p>
linebreaks 过滤器
{{ ""|linebreaks|safe }} {{ simple.newline_text|linebreaks|safe }} {{ simple.long_text|linebreaks|safe }} {{ "john doe"|linebreaks|safe }} # 显示结果 <p>this is a text<br />with a new line in it</p> <p>This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep!</p> <p>john doe</p>
linebreaksbr 过滤器
{{ ""|linebreaksbr|safe }} {{ simple.newline_text|linebreaksbr|safe }} {{ simple.long_text|linebreaksbr|safe }} {{ "john doe"|linebreaksbr|safe }} # 显示结果 this is a text<br />with a new line in it This is a simple text.</p><p>This too, as a paragraph.<br />Right?</p><p>Yep! john doe
linenumbers 过滤器
{{ simple.long_text|linebreaksbr }} # 显示结果 1. This is a simple text. 2. This too, as a paragraph. 3. 4. Right? 5. Yep!