Sanic app 模块主要定义了Sanic类,本文介绍Sanic类的API接口。
Sanic app 模块
该模块主要是类Sanic的定义:
class sanic.app.Sanic(name=None, router=None, error_handler=None, load_env=True, request_class=None, strict_slashes=False, log_config=None, configure_logging=True)
Sanic 类使用的示例:
from sanic import Sanic
from sanic.response import json
app = Sanic()
@app.route("/")
async def test(request):
return json({"hello": "world"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
Sanic类的主要方法是如下几个。
Sanic add_route() 方法/函数
Sanic add_task()方法/函数
Sanic add_websocket_route() 方法/函数
Sanic websocket() 方法/函数
Sanic blueprint() 方法/函数
Sanic create_server() 方法/函数
Sanic exception() 方法/函数
Sanic get() 方法/函数
Sanic post() 方法/函数
Sanic delete()方法/函数
Sanic head(), options(), patch(), put() 方法/函数
Sanic listener() 方法/函数
Sanic middleware() 方法/函数
Sanic route() 方法/函数
Sanic run() 方法/函数
Sanic static() 方法/函数
Sanic url_for() 方法/函数

我的公众号:猿人学 Python 上会分享更多心得体会,敬请关注。
***版权申明:若没有特殊说明,文章皆是猿人学 yuanrenxue.con 原创,没有猿人学授权,请勿以任何形式转载。***
说点什么吧...