将嵌套字典从视图传递到模板 django

Pass nested dictionary from views to template django

所以,我是 Django 的新手,我正在尝试将数据从我的视图传递到模板。我已经了解如何通过经典词典,但我现在需要使用嵌套词典。

比如我有一个字典如下

my_dictionary = {0: {'title': 'Beyond the Soul', 'id': '2Uy66My5oKcBEIW7DvVk3V'},
1: {'title': 'The Groove Cartel Selection', 'id': '1pHtICGI68RmWEKnnP5wGr'},
2: {'title':
 'STMPD RCRDS TOP 50', 'id': '1OIzwJTbrOeZTHvUXf5yMg'},
3: {'title': 'House Party by Axwell', 'id': '1tl4L77FJju5zp9bJC83u8'}}

在我看来我正在返回 return render(request, 'show_playlist.html', my_dictionary ) 但如果我使用 {{ main_playlist[0] }} 它会给出 Could not parse the remainder error

有没有办法访问模板中的嵌套字典?

我已经试过了 answer 但是没有显示任何东西

{% for key, value in main_playlist.items %}
    <p> {{key}}: {{value.title}} </p>
    {% endfor %}

如果要在模板上使用 main_playlist,则必须正确命名上下文数据,因此:

return render(request, 'show_playlist.html', {"main_playlist": my_dictionary} )