Django - skip first row of array

后端 未结 3 465
陌清茗
陌清茗 2021-01-12 12:16

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.

相关标签:
3条回答
  • 2021-01-12 13:07
    {% for a in array %}
      {% if not forloop.first %}
        {{ a }}
      {% endif %}
    {% endfor %}
    

    There is of course forloop.last for the last iteration as well.

    They are all listed in the Django reference.

    0 讨论(0)
  • 2021-01-12 13:08
    {% for a in array|slice:"1:" %}{{ a }}{% endfor %}
    

    See https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#slice for more information.

    0 讨论(0)
  • 2021-01-12 13:12
    {% for a in array %}
    {% if forloop.counter != 1 %}
        {{ a }}
    {% endif %}
    {% endfor %}
    
    0 讨论(0)
提交回复
热议问题