嗨,我想在 django 模板内的 for 循环中检查 2 个或多个条件。我试过了 -
<table>
{% for p, q in products, quantity %}
<tr>
<td>{{ p.p_name }}</td>
<td>{{ q }}</td>
</tr>
{% endfor %}
</table>
但它没有帮助并给出错误 -
'for' statements should use the format 'for x in y': for p, q in products, quantity
知道如何完成任务..??
提前致谢。
最佳答案
您可以使用 zip()
Python 函数在 View 上下文中提供元组列表。然后您可以使用 {% for p, q in new_list %}
循环,其中 new_list
是压缩列表。
关于python - django模板中for循环中的“and”条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30411634/