pymsql-flask

from flask import Flask, jsonify
from flask import abort,request
import json
app = Flask(__name__)


@app.route('/')
def index():
    return 'Hello, World!'


@app.route('/api/orders', methods=['GET'])
def get_orders():
    #return jsonify({'orders': orders})
    import pandas as pd
    import pymysql
    from sqlalchemy import create_engine  
    conn = create_engine('mysql+pymysql://root:[email protected]:3306/test?charset=utf8')  
    sql = 'select * from users'
    data = pd.read_sql(sql, conn)
    return data.to_json()
    

@app.errorhandler(404)
def not_found(error):
    return jsonify({'error':'Not found'}),404


    

if __name__ == '__main__':
    app.run(host='127.0.0.1', port=5632, debug=True)

你可能感兴趣的:(pymsql-flask)