I\'ve written a Python Flask app, and initially used MySQLdb to access MySQL. Later I\'ve switched to flaskext.mysql for the same purposes, but now when I use this module I
I think @alecxe was hinting at this in his last code block, but you can use a DictCursor with the Flask extension as follows:
As well as the Flask MySQL extension you need the DictCursor
from flaskext.mysql import MySQL
from pymysql.cursors import DictCursor
Then simply add the parameter cursorclass=DictCursor
when creating the MySQL object:
mysql = MySQL(cursorclass=DictCursor)
I'm using this in my own Flask app and it seems to be working as expected
Note: I discovered this solution lurking in a comment in the issue queue in the Github repo for the project here. I do wish the library documentation was more than a few lines long.
mysql.get_db() would result into your "connection" object, you can do:
import MySQLdb as mdb
cur = mysql.get_db().cursor(mdb.cursors.DictCursor)
Or, you can also set the default cursorclass
when initializing the extension:
mysql = MySQL(cursorclass=mdb.cursors.DictCursor)