【发布时间】:2018-08-17 14:08:44
【问题描述】:
我有一本看起来像这样的字典:
{
'Team Starwars': {'Luke Skywalker': {('Jedi', 100)}}
'Team helloworld': {'Beginner': {('newbie', 100)}}
}
现在我想在模板中使用 jinja 遍历字典。 我已经尝试了一些东西,但无法正确地遍历它。 我现在的代码如下所示:
{% for team_name in team_resource %}
{% for team, name in team_resource.items %}
{% for role, allocation in subrole %}
{% if forloop.counter0 != 0 %}<br>{% endif %}
{{role}} {{allocation}} %
{% endfor %}
{% endfor %}
team_resource 是我传递给模板的字典,在第一个循环中,我可以访问字典的第一部分并像 Team Starwars 和 Team helloworld' 一样打印出来,但无法访问字典的其余部分。
我应该怎么做?
【问题讨论】:
标签: python dictionary set jinja2