Basic Template Tags and Filters
if
for
for and if
- forloop.counter is always set to an integer representing the number of times the loop has been entered. This is one-indexed, so the first time through the loop, forloop.counter will be set to 1. Here’s an example:
- forloop.parentloop is a reference to the forloop object for the parent loop, in case of nested loops. Here’s an example:
it’s quite a common template requirement to compare two values and display something if they’re equal – and Django provides an {% ifequal %} tag for that purpose.
The {% ifequal %} tag compares two values and displays everything between {% ifequal %} and{% endifequal %} if the values are equal.
This example compares the template variables user and currentuser:
No comments:
Post a Comment