【发布时间】:2021-12-29 11:44:00
【问题描述】:
我的Django 站点中有 2 个列表。
我的views.py:
def index(request):
totalDBElement = [169, 2166, 5413, 635, 635]
elementOrder = ['Rules', 'Questions', 'ParentChild', 'ChildList']
return render(request,'diagnosis/index.html', {'totalDBElement': totalDBElement, 'elementOrder' : elementOrder})
我希望在我的template: 中获得类似的东西
规则:169
问题:2166
ParentChild: 5413
子列表:635
我的template:
{% for i in len(totalDBElement) %}
<h2> {{ totalDBElement[i] }} </h2>
<h2> {{ elementOrder[i] }} </h2>
{% endfor %}
但它会给出如下错误:
Could not parse the remainder: '(totalDBElement)' from 'len(totalDBElement)'
请建议我该如何解决这个问题?
我也想打印
【问题讨论】:
-
stackoverflow.com/a/1466550/15792008 使用 |count 代替 len()