美文网首页
Jinja2实现文章摘要

Jinja2实现文章摘要

作者: vimtest | 来源:发表于2017-09-14 10:14 被阅读0次

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实现文章摘要

      本文链接:https://www.haomeiwen.com/subject/stwrsxtx.html