[Answered ]-Same for with different behavior in Django

3👍

You want the cycle tag.

{% for object in objects %}
  <li class="{% cycle "your-left-class" "your-right-class" %}">
    {{object}}
  </li>
{% endfor %}

-1👍

{% for object in objects %}
   <div class="
      {% if forloop.counter % 2 == 0 %}
         pull-left
      {% else %}
         pull-right
     {% endif %}
   ">
      {{object}}
   </div>
{% endfor %}

Check the for loop in templates.

👤spinus

Leave a comment