【发布时间】:2019-11-15 00:31:23
【问题描述】:
我在 Windows 10 环境中使用 VS 代码来调试 python flask\jinja 应用程序。
Python 代码将数据传递到 html 页面没有问题,{{ formDict }} 正确显示数据。调试显示有数据传递给 javascript。但是,运行到这一行
var dict = json.stringfy('{{ formDict|tojson|safe }}');
产生这个错误
toJson 没有定义
这是不加载 jinja 的 VS 代码问题还是其他问题?有什么解决办法的推荐吗?
Python 代码:
formDict = {"firstname": "Eric", "lastname": "Smith"}
return render_template("appointment.html",formDict=formDict)
html file - appintment.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
<script>
function createPointOption () {
var dict = json.stringfy('{{ formDict|tojson|safe }}');
......
}
</script>
</head>
<body onload="creatPointOption()">
....
<p id="test">{{formDict}}</p>
</body>
</html>
【问题讨论】: