Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Skip the first element in list

Is it possible with django template tags to skip the first element in a list when doing the for loop? For example I want to begin from element 1 instead from 0.

like image 446
starcorn Avatar asked May 08 '12 08:05

starcorn


People also ask

How do you skip elements in a for loop?

You can use the continue statement if you need to skip the current iteration of a for or while loop and move onto the next iteration. In this example, we are looping through a string of my name.

How do you skip a value in Python?

You can use a continue statement in Python to skip over part of a loop when a condition is met. Then, the rest of a loop will continue running. You use continue statements within loops, usually after an if statement.


2 Answers

builtin slice filter

{{ qs|slice:"1:" }}
like image 99
okm Avatar answered Sep 18 '22 11:09

okm


You can e.g. do:

{% if not forloop.first %}
    ...
{% endif %}
like image 28
ohrstrom Avatar answered Sep 17 '22 11:09

ohrstrom