flask server 发表于 2021-04-14 HelloWorld1234567891011from flask import Flaskfrom flask import Requestapp = Flask(__name__)@app.route('/hello')def hello(): return 'Hello World'if __name__=='__main__': app.run(host='0.0.0.0',port=1234) 简单函数回显传入的参数1234567891011121314151617181920import flask as falskapp =falsk.Flask(__name__)@app.route("/predict",methods=["GET","POST"])def predict(): data = {"success":False} # 获取请求参数 params=flask.request.json if(params==None): params=flask.request.json if(params==None): params=flask.request.args if(params!=None): data["response"]=params.get("msg") data["success"]=True return flask.jsonify(data)app.run(host='0.0.0.0') 需要ec2,我用windows本地运行,本地打开localhost:5000,报Internal Server Error 而实际上,Flask启动的服务环境不够稳定也无法承受大量请求的并发,实际部署过程中配合需要WSGI(Web Server Gateway Interface)使用。 1pip install uwsgi