我正在尝试显示其中包含 HTML 标签的内容,如果字符超过 1000,我也想将其截断,但如果文章在截断点。
代码:
{% if article.content_length > 1000 %}
<p>
{{article.content|truncatechars_html:1000|safe|linebreaks}}
</p>
<a href="#">See more...</a>
{% else %}
<p>
{{article.content|safe|linebreaks}}
</p>
{% endif %}
尽管 {{article.content|truncatechars:1000|safe|linebreaks}}
工作正常但是当我将它更改为 {{article.content|truncatechars_html:1000|safe|linebreaks }}
我收到以下错误:
TemplateSyntaxError at/mysite/article/mysite/
无效过滤器:'truncatechars_html'。
最佳答案
确保您使用的是 Django 1.7 或更高版本。 truncatechars_html
过滤器在早期版本中不可用。
关于css - Django 无效过滤器 : 'truncatechars_html' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34613225/