如何将Python字符串和数字列表传递给JavaScript?

时间:2014-04-26 14:29:08

标签: javascript python json list flask

我正在使用烧瓶和javascript。我需要传递一个像这样的python列表:

percentage=["John",89]

我的烧瓶代码是这样的:

@app.route(/graph):
def graph():
    percentage=["John",89]
    return render_template("graph.html",percentage=percentage)

虽然我的javascript执行其他功能。我只是试图显示传递的值。但它根本没有显示出来。

<script>
     document.write({{percentage}});
</script>

传递的值是使用html段落标记显示的。这有效:

<p>{{percentage}}</p>

我尝试过使用json.dumps(百分比),但它无效。我哪里错了?

0 个答案:

没有答案