jinja 2 filter 使用

文檔地址 http://jinja.pocoo.org/docs/templates/#builtin-filtershtml

indentapi

indent(s, width=4, indentfirst=False)安全

Return a copy of the passed string, each line indented by 4 spaces. The first line is not indented. If you want to change the number of spaces or indent the first line too you can pass additional parameters to the filter:ui

{{ mytext|indent(2, true) }}
    indent by two spaces and indent the first line too.

返回字符串,縮進相應的寬度this

若是mytext 是一個html 元素 好比 <p> indent by two spaces and indent the first line too.</p>spa

將會變成 「<p> indent by two spaces and indent the first line too.</p>」code

這不是咱們想要的,這種狀況下應該寫成htm

{{ mytext|indent(2, true)|safe }}
    <p>indent by two spaces and indent the first line too.</p>

safe(value)blog

Mark the value as safe which means that in an environment with automatic escaping enabled this variable will not be escaped.文檔

safe 會將值自動轉義成安全的值,但在

{{ mytext|indent(2, true)|safe }}

表示這個值是安全的,不須要轉義,會將值 直接顯示的模板中

 

。。。。。未完

相關文章
相關標籤/搜索