【发布时间】:2020-05-18 15:05:35
【问题描述】:
这是我在烧瓶应用程序中的代码
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)
返回这个
你好世界 (('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>
【问题讨论】:
-
能否提供 index.html 模板?我相信答案会在那里
-
我在“UPDATE”下添加了文件
标签: mysql sql sql-query-store sqlresultsetmapping flask-mysql