Javascript 无法将数组打印到HTML中

Javascript 无法将数组打印到HTML中,javascript,python,django,Javascript,Python,Django,我有一个从数据库中提取数据的程序,就像这样 视图.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")

我有一个从数据库中提取数据的程序,就像这样

视图.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>

数据={{totals}
console.log(数据)

我可以看到数据库中的数据已经返回到Chrome的控制台,但它不会一直保留在网页上,我也不确定哪里出了问题

也许你应该把
data={{{totals}}
放在
标记之前,或者我不理解你的意思?

我在你的代码中看不到任何html标记的输出。有吗?你把总数放在javascript标记中,而不是html标记中。我认为这是问题所在,现在它正在将所有数据从数据库中打印出来。