I have a myList
list with e.g. 5 elements, but I want to slice it in template by using command:
{% for item in myList|slice:"3" %}
or this command:
{% for item in myList|slice:":3" %}
What's the difference between slice:"x"
and slice:":x"
? (I don't have currently access to machine with django installed but I'm curious)
slice:"3"
and slice:":x"
are both same as they will return first 3 elements from the list
but if you use slice:"2:x"
then it will leave the 2 items from the first of the list and take from 3rd item till the number you mentioned in the x variable, its basically taking a part
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With