版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/y1574406771/article/details/72771018
最近公司在用Sanic框架 ,写法很简洁
例子
from sanic import Sanic ##引入sanic框架
from sanic.response import text,json
app = Sanic() ##创建Sanic类实例
## 第一个参数指定访问 uri 格式,methods 限制请求方式
## 当然你也可以写成这样@app.route("/")
@app.route("/<name>", methods=['GET', 'POST']) ##设置访问路由
def test(request, name):
print("hello")
return text("world")
@app.middleware('request') ##注册请求前置处理
def xxx(request):
print(“xxxx”) ##可以对request做些处理
@app.middleware('response') ##注册请求后置处理
def xxx(response):
print(“xxxx”) ##可以对response做些处理
app.run(host="0.0.0.0", port=8000, debug=True)
Sanic 中还有很多实用的模块
可以去看看
官方文档点我