Ordani Sanchez Ordani Sanchez - 6 months ago 44
Python Question

How to not render a entire string with jinja2

I'm building a blog from start for a homework assignment in Google App Engine in python and I'm using jinja2 to render my html. My problem is that like every blog when an entry is too long; the blog just renders a part of the entry in the main page. I want to do that, when the main page is rendered I took the post from the database and pasted it to jinja. Are there any filters or functions to tell jinja, for example, this string can not be longer than x number?


Look at docs

Jinja2 has truncate filter truncate(s, length=255, killwords=False, end='...'). Example usage

<div>{{ blogpost.text|truncate }}</div>


<div>{{ blogpost.text|truncate(1024, True) }}</div>