gpt4 book ai didi

django - 如何发现内容被截断?

转载 作者:行者123 更新时间:2023-12-04 04:01:25 25 4
gpt4 key购买 nike

我正在尝试构建博客应用,问题是当我在模板中使用标签'truncatewords_html'来截断长度超过指定单词数的帖子时,我需要通过链接链接以完成标题,例如“阅读更多... '截断后。因此,我应该知道该职位是否已被截断。

附言:这是解决问题的Python方法吗?

{% 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 %}

最佳答案

这非常令人费解,但是django有一些怪异的角落。基本上我认为如果在x和x + 1字词处截断字符串长度是否相同,则该字符串尚未被截断...

{% ifnotequal post.body|truncatewords_html:30|length post.body|truncatewords_html:31|length %}
<a href="#">read more...</a>
{% endifnotequal %}

关于django - 如何发现内容被截断?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1802625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com