django-template

for...in... : Same usage as for...in... in python

{% for m in modules %}
{{ forloop.cpunter }} {{ m }}
{% end %}
  • forloop.counter: The number of current iterations, the subscript starts from 1. Display index starts at 1
  • forloop.counter0: The number of current iterations, the subscript starts from 0.
  • forloop.first: return bool type, if it is the first iteration, return true, otherwise return false.
  • forloop.last: return bool type, if it is the last iteration, return True, otherwise return False

ps: 

# The engine needs the template rendering template that comes with django. The 
forloop.first and last can be used to judge whether it is the first (last) iteration. If it is the first iteration {% if forloop.first %} I will output {% endif %}

    {% for s in students %}
        {% if forloop.first %}+  
        { % endif % } 
            is only displayed on the first iteration
        {{ forloop.counter0 }} {{ s }}<br>
    {% endfor %}
 
 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325681042&siteId=291194637