I am trying to use truncatechars in flask. When previously I used truncatechars in django the following code worked
The code (Django):
<div >{{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 >{{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 ':'
CodePudding user response:
In Jinja2 this filter is called truncate:
<div >{{ post.content|safe|truncate(500) }}</div>
