aquaman
aquaman

Reputation: 1658

'and' condition in for loop in django template

Hi I want to check 2 or more conditions in a for loop inside django template. I tried -

<table>
                {% for p, q in products, quantity %}
                    <tr>
                        <td>{{ p.p_name }}</td>
                        <td>{{ q }}</td>
                    </tr>
                {% endfor %}
            </table>

But it did not helped and gave error -

'for' statements should use the format 'for x in y': for p, q in products, quantity

Any idea how can I accomplish the task..??

Thanks in advance.

Upvotes: 2

Views: 1067

Answers (1)

Wtower
Wtower

Reputation: 19912

You can use the zip() Python function to provide a list of tuples in your view context. Then you can loop with {% for p, q in new_list %} where new_list is the zipped lists.

Upvotes: 4

Related Questions