Can someone share example codes in Flask on how to access a MySQL DB? There have been documents showing how to connect to sqlite but not on MySQL.
Thank you very muc
#!/usr/bin/python
from flask import Flask,jsonify,abort, make_response
import MySQLdb
app = Flask(__name__)
db = MySQLdb.connect("localhost", "root", "yourDbPassWord", "DBname")
@app.route('/api/v1.0/items', methods=['GET'])
def get_items():
curs = db.cursor()
try:
curs.execute("SELECT * FROM items")
...
except:
print "Error: unable to fetch items"
return jsonify({"desired: " response})