Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Django filter for truncating characters?

Tags:

python

django

On the Django docs for built in tags and filters they give a filter to truncate words but not characters (letters/numbers/spaces, etc). Is there such a thing available?

like image 510
Vic Avatar asked May 18 '11 21:05

Vic


1 Answers

You can use the slice notation: {{ a_string_variable|slice:":5" }} This would give you the first 5 characters in the string.

like image 120
Kyle Avatar answered Sep 28 '22 19:09

Kyle