管理Cookie
# 设置
@app.post("/create/")
def create_cookie(response: Response):
# 设置cookie对应的key-value值
response.set_cookie(key="name", value="jack")
response.set_cookie(key="id", value="uid123456")
return {"message": "ok"}
# 获取
@app.get("/cookie/get/")
def create_cookie(id: Optional[str] = Cookie(None), name: Optional[str] = Cookie(None)):
# 如果已经设置了Cookie,通过函数参数并指定类型为Cookie,内部会自动获取对应的key-value值
return {"name": name, "id": id}
-------------------------------------------
个性签名:代码过万,键盘敲烂!!!