我正在尝试构建一个博客应用程序,问题是当我在我的模板中使用标签'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 %}
Run Code Online (Sandbox Code Playgroud)