Jinja2使用truncate
可以實現(xiàn)文章摘要
原文鏈接
truncate(s, length=255, killwords=False, end='...')
Return a truncated copy of the string. The length is specified with the first parameter which defaults to 255. If the second parameter is true the filter will cut the text at length. Otherwise it will discard the last word. If the text was in facttruncated it will append an ellipsis sign ("..."). If you want a different ellipsis sign than "..." you can specify it using the third parameter.
第二個參數(shù)為true郊丛,則為硬截斷,如為False边苹,則按上一個單詞截斷买猖,如下例:
{{ "foo bar"|truncate(5) }}
-> "foo ..."
{{ "foo bar"|truncate(5, True) }}
-> "foo b..."