Django - skip the first line of an array

I have a pretty simple question, but I cannot find a simple solution. I would like to iterate over the array in my Django template, but skip the first value.

Let's say I have such an array that I pass my template through a view:

array = ['1', '2', '3', '4', '5']

In my template, I:

{% for a in array%} {{a}} {% endfor%}

How can I do to print only "2" "3" "4" 5, without the first value?

+5
source share
3 answers
{% for a in array|slice:"1:" %}{{ a }}{% endfor %}

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

+13
source
{% for a in array %}
  {% if not forloop.first %}
    {{ a }}
  {% endif %}
{% endfor %}

Of course, forloop.lastfor the last iteration.

Django .

+5
{% for a in array %}
{% if forloop.counter != 1 %}
    {{ a }}
{% endif %}
{% endfor %}
+2

All Articles