如何获取jinja2模板中列表中元素的数量?获取jinja2模板中列表的长度
例如,在Python:
print(template.render(products=[???]))
和Jinja2的
<span>You have {{what goes here?}} products</span>
如何获取jinja2模板中列表中元素的数量?获取jinja2模板中列表的长度
例如,在Python:
print(template.render(products=[???]))
和Jinja2的
<span>You have {{what goes here?}} products</span>
Alex的评论看起来不错,但我仍然与使用范围混淆。 以下工作适用于使用范围内长度的条件。
{% for i in range(0,(nums['list_users_response']['list_users_result']['users'])| length) %}
<li> {{ nums['list_users_response']['list_users_result']['users'][i]['user_name'] }} </li>
{% endfor %}
我们可以检查undefined吗?我必须使用{%如果产品没有...%},这非常累人 – 2017-08-21 04:28:39