这是我在烧瓶应用程序中的代码
from flask import Flask, render_template
from flask_mysqldb import MySQL
import MySQLdb.cursors
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASWPRD'] = ''
app.config['MYSQL_DB'] = 'customer'
mysql = MySQL(app)
@app.route('/')
def index():
cur = mysql.connection.cursor()
cur.execute("SELECT City FROM customer")
data = cur.fetchall()
cur.close()
return render_template ("index.html", name=data)
if __name__ == "__main__":
app.run(debug=True)
返回这个
Hello World (('DHK',), ('KHL',), ('RAJ',), ('COM',))
但是我想展示这样的DHK,KHL,......
我怎样才能得到它并在 HTML 模板中使用它
更新
这是 index.html 文件
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Flask App</title>
</head>
<body>
<head>Hello World</head>
<h1>{{ name }}</h1>
</body>
</html>