如何在Django模板上访问多维字典

gc5*_*gc5 1 python django dictionary django-templates

我试图访问Django模板中的多维字典.我能够查看第一级键,但由于二级键我看不到任何东西.在示例字典中以这种方式组成:

dictionary = {}
dictionary[first_level] = {}
dictionary[first_level][second_level] = {}
...

and so on
Run Code Online (Sandbox Code Playgroud)

从Django模板我使用:

{% for flk in dict %}
    <!-- Using nested for from the following, no output is shown -->
    {% for slk in dict.flk %}
        <th>First level key : {{ flk }} Second level key : {{ slk }}</th>
    {% endfor %}
    <!-- -->
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

我可以使用模型,还是可以使用这个字典?

谢谢

gc5*_*gc5 5

我在这个页面上找到了解决方案 基本上代码变成了

{% for flk, flv in dict.items %}
    {% for slk, slv in flv.items %}
        <th>First level key {{ flk }} Second level key {{ slk }}</th>
    {% endfor %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

每个字典在键(flk, slk)和值中分解的位置(flv, slv).