Question

If I want to get first 5 elements from a list I would do mylist|slice:"5"

but I want a range, let say from 3 to 7. something like mylist[3:8] how would I do that in template

Was it helpful?

Solution

you can just use

{{ mylist|slice:"3:8" }}

OTHER TIPS

Its simple you will have to pass this in the slice filter then:

{{ mylist|slice:"3:8" }}

This filter takes care of all type of slicing you can perform on a list

e.g. All this would work:

{{ mylist|slice:"3:8" }}

{{ mylist|slice:":2" }}

{{ mylist|slice:"3:" }}

{{ mylist|slice:":" }}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top