selfmarket.net
selfmarket.net

Reputation: 139

python flask template return first 150 characters

I want to create meta description on my website, in this moment i have this function for get product description :

{{ product.description|nl2br }}                                 

Need edit this function for get only the first 150 characters for create meta description, is possible this in template ? or need create this function in views.py ?

Upvotes: 4

Views: 6304

Answers (1)

lord63. j
lord63. j

Reputation: 4670

jinja2 has a filter named truncate, the documentation is here:

{{ "foo bar baz"|truncate(9) }}
-> "foo ..."

so, you can try this one:

{{ product.description | truncate(150) }}    

Upvotes: 13

Related Questions