Django substr / substring in templates

As everyone felt leaving a link would be enough, I'll add some code sample from django documents here:

slice filter returns a slice of the list

{{ some_list|slice:":2" }}

If some_list is ['a', 'b', 'c'], the output will be ['a', 'b'].


In python, substrings are accessed as slices; there's a built-in slice filter in django.


You can use the slice filter, though I don't think there's an equivalent to the $length argument.


you can use cut filter e.g. :

{{ value }} -> 'hello world'
{{ value|cut:'hello ' }} -> 'world'