Skip to content

Sanic server demo (in Windows)

代码

python
from sanic import Sanic, Request
from sanic.response import json as resp_json


app = Sanic("app")
SECRET = 'aaaaaaaaaaaaaaaaaaaaa'

@app.get("/")
async def index(r: Request):
    return resp_json({"message": "success"}, status=200)

@app.get("/data")
async def data(r: Request):
    return resp_json({"message": "success"}, status=200)

if __name__ == '__main__':
    app.run(host="127.0.0.1", port=8488, access_log=True, auto_reload=True)

运行

shell
@echo off

poetry init
poetry add sanic
poetry run python app.py

pause

Released under the MIT License.