Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import Flask, jsonify
- from flaskext.mysql import MySQL
- app = Flask(__name__)
- mysql = MySQL()
- # MySQL configurations
- app.config['MYSQL_DATABASE_USER'] = 'xxxxx'
- app.config['MYSQL_DATABASE_PASSWORD'] = 'xxxx'
- app.config['MYSQL_DATABASE_DB'] = 'xxxx'
- app.config['MYSQL_DATABASE_HOST'] = 'xxx.xx.xxx.xxx'
- mysql.init_app(app)
- @app.route('/api')
- def get():
- cur = mysql.connect().cursor()
- cur.execute('''select * from xxx.demo''')
- r = [dict((cur.description[i][0], value)
- for i, value in enumerate(row)) for row in cur.fetchall()]
- return jsonify({'myCollection' : r})
- if __name__ == '__main__':
- app.run( host = "xx.xx.xx.xx" port = xx, debug=True)
- # app.run()
Add Comment
Please, Sign In to add comment