Django template iterate items in template

Django -- Posted on Feb. 28, 2024

Django iterate items in template and create new row  per N items. In the snippet i create new row per 2 items 

              
                <div class="container">
    <div class="row">    
        {% for i in data %}
          <div class="col-2">
              {{i}}
         </div>
            {%if forloop.counter|divisibleby:"2" %}
              </div><div class="row">  
          {%endif%} 
        {%endfor%}
   </div> <!--container-->
                  
   
            

Related Posts