安装(Install)
pip install sanic
Hello, world 应用(Hello, world application)
from sanic import Sanic
from sanic.response import text
app = Sanic("MyHelloWorldApp")
@app.get("/")
async def hello_world(request):
return text("Hello, world.")
运行(Running)
让我们将上面写好的文件保存为 server.py, 然后运行它。
sanic server.app
运行效果