Reputation: 962
I have read through the Jinja documentation and am using the truncate
filter. I have used it exactly as defined in the documentation.
From the docs:
truncate(s, length=255, killwords=False, end=’…’, leeway=None) Return a truncated copy of the string. The length is specified with the first parameter which defaults to 255. If the second parameter is true the filter will cut the text at length. Otherwise it will discard the last word. If the text was in fact truncated it will append an ellipsis sign ("..."). If you want a different ellipsis sign than "..." you can specify it using the third parameter. Strings that only exceed the length by the tolerance margin given in the fourth parameter will not be truncated.
Here is my code:
{% if post.replies.all %}
<ul class="accordion" data-accordion data-multi-Expand="true" data-allow-all-closed="true">
{% for reply in post.replies.all %}
<li class="accordion-item" data-accordion>
<a href="#" class="accordion-title">{{reply.by}}: {{reply.content|truncate(14)}}</a>
<div class="accordion-content" data-tab-content>
<img src="{{ reply.by.profile.img_url }}" class="thumbnail" width="50" height="50">
<p>{{ reply.content }}</p>
</div>
</li>
{% endfor %}
</ul>
{% endif %}
I get the following traceback after testing:
What am I doing wrong?
Upvotes: 3
Views: 5026
Reputation: 599490
You are quite simply not using Jinja. You are using the Django template language.
Django's built-in filters are documented here; the filter that truncate strings is called truncatechars
. You also need to use Django syntax to pass the parameters to the filter.
{{reply.content|truncatechars:14}}
Upvotes: 12