flask使用模板

flask常用代码模板

from flask import Flask, request,jsonify
import requests

app = Flask(__name__)


@app.route('/')
def index():
    return '<h1>test</h1>'


@app.route('/user/<username>')
def show_user_profile(username):
    # show the user profile for that user
    return 'User %s' % username


@app.route('/go', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        username = request.form['name']
        result = aad()
        return jsonify({'error': 0, 'msg': '输入ok'})
    else:
        return 'get'


def aad():
    que = [1, 2, 3, 44, 5, 6, 7, 8] + [0] * 348
    input = [que]
    # print(input)
    url = 'http://localhost:8501/v1/models/aad_serve:predict'
    response = requests.post(url, json={"instances": input})
    # print(response.text)
    return (response.text)


if __name__ == '__main__':
    app.run(debug=True, port=8777)

posted @ 2019-07-23 14:08  潘峰YiRan  阅读(279)  评论(0编辑  收藏  举报