写一个简单的python服务测试

发布时间:2024年01月22日

1:引用sanic

pip install sanic

2: 引用sanic 跨域

3:

 #-*- coding: UTF-8 -*-
# !/usr/bin/python
# @time     :2022/2/22 21:43
# @author   :Mo
# @function :get/post of sanic


from sanic.response import json, text
from sanic import Sanic, request
from sanic_cors import CORS


app = Sanic("test")
app.config.HEALTH = True
CORS(app)

#这是个测试
@app.route("/test/haha", methods=["GET"])
async def calculate_add(request):
    """ 分类 """
    params = request.args
    print(request)

    tt = params.get("tt", 0)
    
    print(tt)

    data_dict = {"c": tt}
    status_code = 200
    res_dict = {"code": status_code,
                "data": data_dict,
                "message": "success"
                }
    return json(res_dict, status=status_code, ensure_ascii=False)


if __name__ == "__main__":
    app.run(single_process=True,
            access_log=True,
            host="0.0.0.0",
            port=1111,
            workers=1,
            )

4:查看

文章来源:https://blog.csdn.net/vily_luky/article/details/135748991
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。