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>
Or
<div>{{ blogpost.text|truncate(1024, True) }}</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With