Issue
I am trying to use truncatechars in flask. When previously I used truncatechars in django the following code worked
The code (Django):
<div class="preview">{{post.content |safe| truncatechars:500}}</div>
But when I use truncatechars in flask it throws an error saying jinja2.exceptions.TemplateAssertionError: No filter named 'truncatechars_html'.
The code (Flask):
<div class="preview">{{post.content |safe| truncatechars(500)}}</div>
When I used ":" instead of brackets "()" it throwed an error saying jinja2.exceptions.TemplateSyntaxError: expected token 'end of print statement', got ':'
Solution
In Jinja2 this filter is called truncate
:
<div class="preview">{{ post.content|safe|truncate(500) }}</div>
Answered By - Dauros
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.