我有一个Flask
应用程序,我想连接MYSQL
数据库和SELECT
数据库中的信息。当我运行我的代码时,我遇到以下错误:
KeyError: 'MYSQL_DATABASE_SOCKET
我的代码是:
from flaskext.mysql import MySQL
import pymysql
from flask import render_template, redirect
app = Flask(__name__)
mysql = MySQL()
# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = ''
app.config['MYSQL_DATABASE_DB'] = 'market_DB'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
app.config['MYSQL_DATABASE_PORT'] = '3306'
mysql.init_app(app)
@app.route('/')
def product():
conn = mysql.connect()
cursor = conn.cursor()
#return "ok"
cursor.execute("SELECT * FROM Tbl_product")
productDetails= cursor.fetchall()
return render_template('product.html', productDetails=productDetails)
if __name__ == '__main__':
app.run(debug=True)
你能帮助我吗?