我正在尝试输出线程的文本,但是我不想显示线程的整个文本。我只想显示它的一个小预览(前100个字符)。问题是TemplateSyntaxError
当我尝试对它进行子串处理时出现了问题。
{% for post in posts %}
<div>
<p>Title: {{ post.title }}</p>
<p>Posted on: {{ post.created_on }}</p>
<p>User: {{ post.author }}</p>
<p>{{ {% post.text[0:100] %} | safe }}</p>
</div>
<br>
{% endfor %}
这是错误:
Could not parse some characters: |{% post.text[0:100] %}| | safe
您可以使用django slice过滤器来模拟切片:
{{ some_list|slice:":2" }}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句