Django - 跳过第一行数组

Joh*_*nna 5 arrays django django-templates

我有一个相当简单的问题,但我似乎无法找到一个简单的解决方案.我想在我的Django模板中迭代一个数组但跳过第一个值.

假设我有一个这样的数组,我通过视图传递给我的模板:

array = ['1', '2', '3', '4', '5']
Run Code Online (Sandbox Code Playgroud)

在我的模板中,我做:

{%表示数组%} {{a}} {%endfor%}

我怎么能只打印'2''3''4''5',没有第一个值?

Jer*_*wis 15

{% for a in array|slice:"1:" %}{{ a }}{% endfor %}
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#slice.


Som*_*ude 5

{% for a in array %}
  {% if not forloop.first %}
    {{ a }}
  {% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

当然也有forloop.last最后一次迭代.

它们都列在Django 参考中.