Bob Billinger
Bob Billinger

Reputation: 31

Unable to print array into HTML

I have a program which is pulling data from the database like so.

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()})

From here I'm trying to print into HTML like so

final.HTML

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

I can see that the data from the database has returned to the console in Chrome but it won't persist onto the web page and I'm not sure where I'm going wrong. Console output Chrome

Upvotes: 0

Views: 55

Answers (1)

Johan Willfred
Johan Willfred

Reputation: 851

Maybe you should put data = {{totals}} before </body> tag, or I did not understand you ?

Upvotes: 1

Related Questions