【发布时间】:2009-11-26 09:41:12
【问题描述】:
我正在尝试构建一个博客应用程序,问题是当我在模板中使用标签“truncatewords_html”来截断长于指定字数的帖子时,我需要通过一些标题链接以完成帖子,例如“阅读更多” ...' 截断后。所以我应该知道帖子是否被截断。
P.S.:这是解决问题的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 %}
【问题讨论】: