Is there is some good way to iterate through list in django template and print just items with index which is fo开发者_JAVA技巧r example 3,6,9 and so on...
Let's imagine I have list like this:
({'title':'first'}, {'title':'second'}, {'title':'third'}, .... {'title':'ninth '})
And in template I want to see just:
third
sixth
ninth
I know how to pass variable to template, I construct in a view, but just need the way how to iterate through them in template and print just what I want.
Or I need to construct list (or dictionary maybe) somehow differently? Using latest Django.
Thanks, Ignas
The slice
filter will allow you to slice a sequence just as you would in Python.
{{ mylist|slice:"2::3" }}
精彩评论