【发布时间】:2021-04-28 09:06:15
【问题描述】:
我有一个数组:
videos = [{
"id":1,
"title": "Как построить открытую террасу к дому своими руками",
"src": "http://videohost.me/hDX4hWWV5Ok.mp4",
},{
"id": 2,
"title": "How To Learn Anything 10x Faster",
"description": "Interested in learning more about Charisma University? You’re going to spend thousands and thousands hours learning over the course of your life. What’s crazy is that despite the fact that we have all those hours sitting in the classroom, learning musical instruments, martial arts, business, language, whatever - no one teaches us how to optimize that learning experience.",
"src": "http://videohost.me/YLwFbwPbq.mp4",
}]
我尝试在网站中以 html 格式打印字典中的所有标题:
{% for video in videos %}
<h2>{{ video.title}} </h2>
<h2>{{ video.id}} </h2>
<p></p>
<video src="{{ video.src }}" />
{% endfor %}
但它只显示第一个标题。是什么原因,我该如何解决我的问题?
【问题讨论】:
-
我不明白你如何通过
video.id访问视频中的密钥,afaik python 不允许这样做。我认为应该是video["id"]。此外,神社代码似乎没问题。
标签: python html arrays dictionary jinja2