Je kunt dit antwoord volgen:https://stackoverflow.com/a/41388992/3129414
Bestaande codewijziging:
- gebruik
DictCursor
inMySQL
initialisatie - verwijder
dictionary=True
van cursor - gebruik
json
pakket om woordenboekitems naar json-indeling te converteren
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)
Schermafbeelding: