Anup Bhattarai
Anup Bhattarai

Reputation: 191

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

Upvotes: 0

Views: 267

Answers (1)

Dauros
Dauros

Reputation: 10557

In Jinja2 this filter is called truncate:

<div class="preview">{{ post.content|safe|truncate(500) }}</div>

Upvotes: 2

Related Questions