How to find that the content is truncated?

后端 未结 4 1215
误落风尘
误落风尘 2021-01-02 05:05

I\'m trying to build a blog app and the problem is when I use tag \'truncatewords_html\' in my template to truncate posts longer than specified number of words, I need to li

4条回答
  •  一生所求
    2021-01-02 05:35

    This is pretty convoluted but django has some weird corners. Basically I figure if the string length is the same if you truncate at x and x+1 words then the string has not been truncated...

    {% ifnotequal post.body|truncatewords_html:30|length post.body|truncatewords_html:31|length %}
       read more...
    {% endifnotequal %}
    

提交回复
热议问题