flask 部署微服务
from flask_restful import Resource, reqparse, request, Apifrom flask import Flaskparser = reqparse.RequestParser()parser.add_argument("status")class Recomend_API(Resource):def post(self):args = parser
·
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask_restful import Resource, reqparse, request, Api
from flask import Flask
parser = reqparse.RequestParser()
parser.add_argument("status")
class Recomend_API(Resource):
def post(self):
args = parser.parse_args()
print(args)
status = args['status']
print(status)
result=status+' and i love python '
return result
app = Flask(__name__)
api = Api(app)
api.add_resource(Recomend_API, '/')
if __name__ == '__main__':
app.run()
- 保存文件micro.py
gunicorn -w 3 -b 127.0.0.1:8000 micro:app
- 用gunicorn 开多个进程
from requests import put, get,post
response=post('http://127.0.0.1:8000', data={'status': 'I am Thomas'})
print(response.json())
print(response.text)
- 向服务器发请求
I am Thomas and i love python
"I am Thomas and i love python "
更多推荐
已为社区贡献2条内容
所有评论(0)