开发者

django template: iterate and print just items with index for example 3,6,9

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" }}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜