Django substr / substring in templates


Question

Could someone tell me, does the method like substr in PHP (http://pl2.php.net/manual/en/function.substr.php) exist in Django templates?

1
20
8/31/2011 4:38:08 PM

Accepted Answer

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

27
8/31/2011 4:44:41 PM

you can use cut filter e.g. :

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon