Du kan følge dette svar:https://stackoverflow.com/a/41388992/3129414
Eksisterende kodeændring:
- brug
DictCursor
iMySQL
initialisering - fjern
dictionary=True
fra markøren - brug
json
pakke til at konvertere ordbogselementer til json-format
app.py
:
import json
from flask import Flask
from flaskext.mysql import MySQL
from pymysql.cursors import DictCursor
app = Flask(__name__)
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = '123'
app.config['MYSQL_DATABASE_DB'] = 'practice_db'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql = MySQL(cursorclass=DictCursor)
mysql.init_app(app)
conn = mysql.connect()
@app.route("/", methods=['GET'])
def home():
email_address = '[email protected]'
cursor = conn.cursor();
cursor.execute(
'SELECT * FROM user_table WHERE email = (%s)', (email_address,)
)
users = cursor.fetchall()
return json.dumps(users)
app.run(debug=True)
Skærmbillede: