在我的服务器.py,我有一个记录姓名的列表:
data = [
"Jim",
"Stanley",
"Michael",
"Kevin",
"Kelly"
]
执行{data | tojson}}对我不起作用,因为这种格式的数据是不可序列化的。执行return render_template('ppc.html', data=data)
似乎也不允许js文件访问数据服务器.py. 我也尝试过'{{data}}'
这种格式在一些帖子中被推荐,但这些似乎都不起作用。有人有别的办法吗?你知道吗
Tags:
使用
jsonify
方法。它将允许从view
返回list
。jsonify的文档。你知道吗下面是一个如何使用Javascript在模板中加载数据的示例。你知道吗
文件夹结构:
app.py
:simple.html
:demo.js
:输出:
相关问题 更多 >
编程相关推荐