我有一个从数据库中提取数据的程序。
Views.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>
答案 0 :(得分:1)
也许你应该在data = {{totals}}
代码前加</body>
,或者我不理解你?