我是Django的新手,请帮助我,我读了一些文章vlog似乎找不到正确的代码,这是我在views.py中的代码,我希望它显示在HTML index.html]中>结果是它不会显示,我不知道我的代码出了什么问题]
from django.shortcuts import render from django.http import JsonResponse,HttpResponse import requests import pandas as pd import json def home(request): response = requests.get('https:api').text # li = list(response.split(",")) res = json.loads(response) maleCount = 0 femaleCount = 0 for i in res: if i['gender'] == 'M': maleCount += 1 else: femaleCount += 1 TotalCount =[ { "name": "MALE", "data": [maleCount]}, { "name": "FEMALE", "data": [femaleCount] } ] return render(request,'index.html',{'data':TotalCount})
这里是index.html tru views.py中html中的代码,它无法以html显示我的数据,看来我的代码无法工作。我的代码有什么问题?请帮助谢谢
<!doctype html> <html lang="en"> <body> <div class="container-fluid"> <div class="border" id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div> </div> <script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/modules/exporting.js"></script> <script src="https://code.highcharts.com/modules/export-data.js"></script> <script> Highcharts.chart('container', { chart: { type: 'column' }, title: { text: 'Total fruit consumtion, grouped by gender' }, xAxis: { categories: ['asd','asd'] }, yAxis: { allowDecimals: false, min: 0, title: { text: 'Number of fruits' } }, tooltip: { formatter: function () { return '<b>' + this.x + '</b><br/>' + this.series.name + ': ' + this.y + '<br/>' + 'Total: ' + this.point.stackTotal; } }, plotOptions: { column: { stacking: 'normal' } }, series: data }); </script> </body> </html>
我的代码有什么问题?
[我是Django的新手,请帮助我,我读了一些文章vlog似乎找不到正确的代码,这是我在views.py中的代码,我希望它显示在HTML index.html中,结果是它不会。 ..
如果要在html代码中使用上下文数据,则需要将其放在双括号中:series: {{data}}