I'm making a blog with Django and it's hard to see even if there is a long sentence on the home, so I was looking for a way to abbreviate it, and I found something like this, so I will share it.
Django version = 2.2.4 Python version = 3.8.2
home_list.html
<p>{{ post.text|linebreaksbr|truncatechars:250 }}</p>
It may be a little confusing, but only the last "truncatechars" is specifically relevant to this article.
By changing the number there to your liking, it will be abbreviated as ... from the next character.
Recommended Posts