嗨,我想检查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函数在视图上下文中提供元组列表。然后,你可以循环使用{% for p, q in new_list %}
,其中new_list
是压缩列表。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句