Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django substr / substring in templates

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

like image 736
Jazi Avatar asked Aug 31 '11 16:08

Jazi


3 Answers

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

like image 54
Ismail Badawi Avatar answered Oct 14 '22 11:10

Ismail Badawi


you can use cut filter e.g. :

{{ value }} -> 'hello world'
{{ value|cut:'hello ' }} -> 'world'
like image 6
Farsheed Feeruzy Avatar answered Oct 14 '22 10:10

Farsheed Feeruzy


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

like image 5
Wooble Avatar answered Oct 14 '22 10:10

Wooble