我使用的是flask框架和MySQL数据库连接器。在
我做了以下事情:
from flaskext.mysql import MySQL
mysql = MySQL()
## app.config database configuration code
mysql.init_app(app)
conn = mysql.connect()
cursor = conn.cursor();
cursor.execute(
'SELECT * FROM customer WHERE email = (%s)', (username,)
)
user = cursor.fetchone()
我可以使用user[8]
之类的索引访问用户列(我需要执行一次查询并检查列号),但是当我尝试指定
我知道错误了
'TypeError: cursor() got an unexpected keyword argument 'dictionary''
在使用flaskmysql时,有没有一种方法可以获得字典格式的查询结果?在
你可以按照这个答案:https://stackoverflow.com/a/41388992/3129414
现有代码修改:
MySQL
初始化中使用DictCursor
dictionary=True
json
包将字典项转换为json格式app.py
:截图:
相关问题 更多 >
编程相关推荐