Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The difference between django slice filter usages

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)

like image 974
lukaszkups Avatar asked Jun 30 '17 04:06

lukaszkups


1 Answers

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

like image 60
Exprator Avatar answered Sep 28 '22 03:09

Exprator