【发布时间】:2022-01-31 20:58:58
【问题描述】:
我正在尝试在 Django 项目中使用此代码 sn-p。
如何访问每个键的值(列表)?
并显示列表项?
我想使用 Jinja 显示这样的表格。 有可能吗?
| key | values |
|---|---|
| 100 | 1,2 |
| 200 | 3,4 |
| 300 | 5,6 |
| 400 | 7,8 |
表中可能有数千行。
def index(request):
data = {
100: [{'childId': 1, 'childStructure': 'Leaf'}, {'childId': 2, 'childStructure': 'Intermediate'}],
200: [{'childId': 3, 'childStructure': 'Intermediate'}, {'childId': 4, 'childStructure': 'Leaf'}],
300: [{'childId': 5, 'childStructure': 'Leaf'}, {'childId': 6, 'childStructure': 'Intermediate'}],
400: [{'childId': 7, 'childStructure': 'Intermediate'}, {'childId': 8, 'childStructure': 'Leaf'}],
}
return render(request,'index.html', {'data': data})
【问题讨论】:
标签: dictionary jinja2 show