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:查看