FastAPI系列:设置响应状态码

设置响应状态码

from fastapi import status
from fastapi.responses import JSONResponse

# 方式一
@router.get("/user", status_code=status.HTTP_202_ACCEPTED)
def user_index():
    return {"msg": "user_index"}

# 方式二
@router.get("/user")
def user_index():
    return JSONResponse(content={"msg": "ok"}, status_code=status.HTTP_201_CREATED)
posted @ 2024-02-28 17:35  我在路上回头看  阅读(38)  评论(0编辑  收藏  举报