Javascript 如何从Django视图访问我的模板中的对象?
我需要显示数据中存在的每个对象的属性。如何访问模板中的对象 视图.pyJavascript 如何从Django视图访问我的模板中的对象?,javascript,django,ajax,chart.js,Javascript,Django,Ajax,Chart.js,我需要显示数据中存在的每个对象的属性。如何访问模板中的对象 视图.py data = [] for e in rep: data.append({ 'time' : e.time, 'power' : e.power }) return JsonResponse({'data':data},status=200) 模板 success : function(response){ console.
data = []
for e in rep:
data.append({
'time' : e.time,
'power' : e.power
})
return JsonResponse({'data':data},status=200)
模板
success : function(response){
console.log(response)
var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: [***here i need to access my objects***],
datasets: [{
label: "Consumption",
data: [{% for e in data %}'{{ e.power }}',{% endfor %}]}})
}
问候。上面显示的成功函数是我的ajax调用中的成功函数。上面显示的成功函数是我的ajax调用中的成功函数。