Sanic框架(二)
文章目录 Sanic Sanic Cookies读写 读取cookies 写入cookies cookies属性 Sanic路由 url_for方法建立路由 Sanic静态文件 Sanic中间件 提前响应 监听器 监听器的注册 添加任务 Sanic Sanic Cookies读写 写web,Cookies会经常用到。Sanic可以读写Cookies,并以key-value(键值对)的方式存储。 读取cookies from sanic.response import text @app.route("/cookie") async def test(request): test_cookie = request.cookies.get('test') return text("Test cookie set to: {}".format(test_cookie)) 写入cookies from sanic.response import text @app.route("/cookie") async def test(request): response = text("There's a cookie up in this response") response.cookies['test'] = 'It worked!' response.cookies['test'][