【发布时间】:2021-07-17 08:31:19
【问题描述】:
嗨,我是 django 的新手,我正在尝试使用 django 视图在模板中打印 for 循环结果,但我无法打印所有行
我的看法:
def upload(request):
cells= [(1,2,3,4),(3,3,4,5)]
i = 0
for cell in cells:
a,b,c.d = cell[0],cell[1],cell[2],cell[3]
I=[b+d,a+c]
i=i+1
print(I)
return render(request,'res.html',{"text":I})
res.html:
{% for i in text %}
<div class="row">
{{ i }}
</div>
{% endfor %}
when I tried only for loop in python IDE my output is
[6, 4]
[8, 7]
but when I tried in django view I am getting only first row
[6, 4] and also not able to print this in res.html
请提前帮我解决这个问题
【问题讨论】:
标签: python django for-loop django-views django-templates