如何在django中为javascript变量赋值

如何在django中为javascript变量赋值,javascript,python,json,django,Javascript,Python,Json,Django,我试图给django中的javascript变量赋值。我需要javascript变量的值,比如 var chartData = [{ section: "Czech Republic", attempted: 301.90 }, { section: "Ireland", attempted: 201.10 }]; 在d

我试图给django中的javascript变量赋值。我需要javascript变量的值,比如

var chartData = [{
                section: "Czech Republic",
                attempted: 301.90
            }, {
                section: "Ireland",
                attempted: 201.10
            }];
在django视图中,我使用以下代码生成和呈现json数据

i = 0
    chart1Data = []
    while(i<len(totalSectionsJson)):
        chart1Data.append({'section':totalSectionsJson[i].encode('utf8'),'attempted':sectionTotalAttempted[i]})
        i = i+1
    chart1DataExport = json.dumps(chart1Data)

我需要删除
尝试
部分
中的引号。我该怎么做呢?

你最好在
js
中进行转换,比如
var chartData=[chart1Data中x的转换]
(抱歉不熟悉js语法),希望这有帮助为什么需要删除引号?Json需要它们,javascript不在乎。或者,将
chart1DataExport
作为字符串文本传递,并在javascript代码中使用Json.parse。@knbk您能再解释一下吗
var chartData = [{"attempted": 0, "section": "section"}, {"attempted": 0, "section": "section2"}, {"attempted": 0, "section": "section3"}];