我正在嘗試構建一個博客應用程序,問題是當我在我的模板中使用標記'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 %}
+1檢查顯示器是否超過長度的簡單方法。簡單,工作正常。 –