Django template tag to truncate text

grigy picture grigy · Mar 8, 2011 · Viewed 80.6k times · Source

Django has truncatewords template tag, which cuts the text at the given word count. But there is nothing like truncatechars.

What's the best way to cut the text in the template at given char-length limit?

Answer

Banjer picture Banjer · Apr 24, 2012

This has recently been added in Django 1.4. e.g.:

{{ value|truncatechars:9 }}

See doc here