我正在尝试构建一个博客应用程序,问题是当我在模板中使用标签“truncatewords_html”来截断长于指定字数的帖子时,我需要通过一些标题链接以完成帖子,例如“阅读更多... ' 截断后。所以我应该知道帖子是否被截断。
PS:这是解决问题的pythonic方法吗?
{% ifequal post.body|length post.body|truncatewords_html:max_words|length %}
{{ post.body|safe }}
{% else %}
{{ post.body|truncatewords_html:max_words|safe }}<a href="{{ post.url}}">read more</a>
{% endifequal %}