Guest User

Untitled

a guest
Feb 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. from flask import Flask, jsonify
  2. from flaskext.mysql import MySQL
  3.  
  4. app = Flask(__name__)
  5. mysql = MySQL()
  6.  
  7. # MySQL configurations
  8. app.config['MYSQL_DATABASE_USER'] = 'xxxxx'
  9. app.config['MYSQL_DATABASE_PASSWORD'] = 'xxxx'
  10. app.config['MYSQL_DATABASE_DB'] = 'xxxx'
  11. app.config['MYSQL_DATABASE_HOST'] = 'xxx.xx.xxx.xxx'
  12.  
  13. mysql.init_app(app)
  14.  
  15. @app.route('/api')
  16. def get():
  17. cur = mysql.connect().cursor()
  18. cur.execute('''select * from xxx.demo''')
  19. r = [dict((cur.description[i][0], value)
  20. for i, value in enumerate(row)) for row in cur.fetchall()]
  21. return jsonify({'myCollection' : r})
  22.  
  23. if __name__ == '__main__':
  24. app.run( host = "xx.xx.xx.xx" port = xx, debug=True)
  25. # app.run()
Add Comment
Please, Sign In to add comment