0
点赞
收藏
分享

微信扫一扫

flask 部署微服务

程序员伟杰 2023-01-13 阅读 114


#!/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 "


举报

相关推荐

0 条评论