# pip install sanic
from sanic import Sanic
from sanic.response import json,file
app=Sanic("app")
'''
请求
get 获取参数 request.args.get("")
post 获取参数 request.form.get(""),
获取文件 request.files.get("")
路由参数 <id>,不传默认为空字符串
repost.[method,ip,port,headers,socket->["127.0.0.1","65253"],
响应
json,file,stream,file_stream,
'''
@app.route('/<id>',methods=['POST'])
async def test(request,id):
name=request.form.get("name")
if id:
return json({"json":name,"id":id})
return json({"json": name, "null_id": id})
if __name__ == '__main__':
app.run(host="0.0.0.0",port=8000,debug=True)