What is a Django filter for truncating characters?

In Django docs for inline tags and filters, they provide a filter to truncate words, but not characters (letters / numbers / spaces, etc.). Is there such a thing?

+4
source share
4 answers

You can use fragment notation: {{ a_string_variable|slice:":5" }} This will give you the first 5 characters in a line.

+5
source

Starting with Django 1.4, truncatechars now a built-in filter in the release.

https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#truncatechars

+5
source

I used this before and worked great:

http://djangosnippets.org/snippets/194/

+1
source

It was a feature request for 4 years, but finally landed in the trunk, as I understand it https://code.djangoproject.com/ticket/5025 - so weve to wait for the next release or use of the trunk.

0
source

All Articles