Django - 跳过数组的第一行 [英] Django - skip first row of array
本文介绍了Django - 跳过数组的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个相当简单的问题,但我似乎找不到简单的解决方案.我想遍历 Django 模板中的数组,但跳过第一个值.
I have a fairly simple question, but I can't seem to find a simple solution to it. I'd like to iterate through an array in my Django template but skip the first value.
假设我有一个这样的数组,我通过视图传递给我的模板:
Let's say I have an array like this that I pass to my template through a view:
array = ['1', '2', '3', '4', '5']
在我的模板中:
{% for a in array %}{{ 一个 }}{% endfor %}
{% for a in array %} {{ a }} {% endfor %}
如何只打印 '2' '3' '4' '5',而不打印第一个值?
How can I do to only print '2' '3' '4' '5', without the first value ?
推荐答案
{% for a in array|slice:"1:" %}{{ a }}{% endfor %}
参见 https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#slice 了解更多信息.
See https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#slice for more information.
这篇关于Django - 跳过数组的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文