Jinja2实现文章摘要

Jinja2使用truncate可以实现文章摘要
原文链接

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.

第二个参数为true,则为硬截断,如为False,则按上一个单词截断,如下例:

{{ "foo bar"|truncate(5) }}
    -> "foo ..."
{{ "foo bar"|truncate(5, True) }}
    -> "foo b..."

你可能感兴趣的:(Jinja2实现文章摘要)