I'm trying to output to a Django template one row that has four DIVs:
<div class="row">
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
<div class="col-md-3">...</div>
</div>
I need to have two nested For Loops so that each time the fourth DIV is outputted, it will create a new row. In Java, it would be like this:
for(int i = 0; i < object_list.length; i++){
<div class="row">
for(int j = 0; j < 4; j++){
<div class="col-md-3">
}
}
The code I'm using in the template is:
{% for object in object_list %}
{% with object|search as search_results %}
{% if search_results == 'Post' %}
[need to fill in appropriate HTML]
{% endif %}
{% endwith %}
{% endfor %}
How can I accomplish this?
UPDATE: This didn't exactly use nested for loops, but the below code solved my issue:
<div class="row">
{% for object in object_list %}
{% with object|search as search_results %}
{% if search_results == 'Address' %}
<div class="col-3">
<div class="iq-card">
<div class="">{{ user.username }}</div>
</div>
</div>
{% endif %}
{% endwith %}
{% endfor %}
</div>