'How to use "truncatechars" in flask? ( Error : No filter named 'truncatechars'. )

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 ':'



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source