gpt4 book ai didi

python - 迭代模板中的 dic 列表

转载 作者:太空宇宙 更新时间:2023-11-03 18:42:39 24 4
gpt4 key购买 nike

客户列表

   {'clients': [
{'id': 357995, 'value': 1.0},
{'id': 369743, 'value': 0.9}
]}
<小时/>
{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% for user in client %}
{% raw user.id %}
{% raw user.value %}
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}

预期输出:

357995
1.0

369743
0.9

问题是模板中的循环错误。我如何访问 id 和值?

这是一个tornado模板,但我认为这与django类似。

更新:

{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% raw client %} // outputs the clients_list
{% for user in client %}
{% raw user %} outputs 'clients'
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}

最佳答案

这是解决方案。

{% try %}
{% if clients_list %}
{% for client in clients_list %}
{% for user in client['clients'] %}
{% raw user['id'] %}
{% raw user['value'] %}
{% end %}
{% end %}
{% end %}
{% except %}
{% end %}

关于python - 迭代模板中的 dic 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20195506/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com