胖蔡说技术
随便扯扯

标签:sanic框架

Python

Sanic中装饰器的使用

胖蔡阅读(624)赞(1)

处理程序装饰器 由于sanic处理程序是简单的python函数,所以可以以类似于flask的方式将修饰器应用于它们。一个典型的用例是,当您希望在执行处理程序的代码之前运行一些代码时。 授权修饰器 假设您希望检查用户是否有权访问特定端点。...

Python

Sanic 路由

胖蔡阅读(673)赞(0)

路由允许用户为不同的URL端点指定处理程序函数。 基本路线如下所示,其中 app 是的实例 Sanic 班级: from sanic.response import json @app.route("/") async def test(r...

Python

Sanic 响应

胖蔡阅读(682)赞(1)

在中使用函数 sanic.response 创建响应的模块。 纯文本 from sanic import response @app.route('/text') def handle_request(request)...

Python

Sanic 请求数据

胖蔡阅读(706)赞(0)

当端点接收到HTTP请求时,route函数被传递给 Request 对象。 以下变量可以作为上的属性访问 Request 物体: json (任意)-JSON正文 from sanic.re...