S
S
Siberian_12018-10-21 16:25:20
Django
Siberian_1, 2018-10-21 16:25:20

How to get another array element with current iteration in django template loop?

There is a template in which q_t and q_p are passed, they contain the same number of elements:

{% for q in q_t.all %}
<div class="row">
    <div class="col-md-8">
         {{q.q_text}}

    </div>
     <div class="col-md-4">
         <a href="#">{{ q_p.{{forloop.counter0}}}}</a>
    </div>
</div>
<br>
{% endfor %}

As I understand it, q_p.0 will return 0 array element, and so on.
I need to take the array element q_p with the current iteration of the loop in the loop.
Tried in different ways:
<a href="#">{{q_p.{{forloop.counter0}}}}</a>
<a href="#">{{q_p.forloop.counter0}}</a>
<a href="#">{{q_p}}.{{forloop.counter0}}</a>

But it doesn't work out

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question