【发布时间】:2020-08-02 19:19:14
【问题描述】:
我在运行我的 web 应用程序时收到此错误。它说在这里发现了错误:
var rows = ({'CurrentLocation': 'Norwich'}, {'CurrentLocation': 'Sheringham'}, {'CurrentLocation': 'Cambridge'})
这是我的代码:
def search():
cursor = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor.execute("SELECT CurrentLocation FROM driver WHERE OnJourney=0")
rows = cursor.fetchall() # data from database
return render_template("Search.html", rows=rows)
var rows = {{ rows }}
var row;
var locations = [];
for (row in rows) {
locations.push(row['CurrentLocation']);
}
var location;
for (location in locations) {
var origin = location;
}
有什么方法可以将字典从 python 传递到 javascript 而不会出现此错误?感谢您的帮助
【问题讨论】:
-
尝试将第一个代码示例中的 & 字符替换为对应的字符。('CurrentLocation') 或者根本不使用它们
-
&#39是'所以我认为你在某处重复引用了你的文字 -
我从 python 获取文本,我无法更改文本,它是从 mysql 获取的
标签: javascript python html