无法将数组打印到HTML中

2024-09-29 23:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个从数据库中提取数据的程序

视图.py

def final(request):
total = []
name = []
k = 0
for i in Question.objects.raw("SELECT name, question1, question2, question3, question4, question5, question6, question7, question8, question9, question10 FROM music_question"):
    name.append(str(i.name))
    total.append(int(i.question1) + int(i.question2) + int(i.question3) + int(i.question4) + int(i.question5)
                 + int(i.question6) + int(i.question7) + int(i.question8) + int(i.question9) + int(i.question10))
return render(request, 'music/final.html', {"totals": total, "names": name, "rows": Question.objects.all()})

从这里我试着打印成HTML,就像这样

final.HTML

    </body>
<script type=text/javascript>
data = {{totals}}
console.log(data)
</script>
</html>

我可以看到数据库中的数据已经返回到Chrome的控制台,但它不会持久存在于网页上,我也不知道我哪里出错了Console output Chrome


Tags: 数据name数据库objectsrequestfinalinttotal

热门问题