FastAPI sql 转换 json

  • 自定义接口统一返回时, 转换 dict , 去除密码

# 增
@app.post('/api/users')
async def get_user(user: UserCreate, db: Session =  Depends(get_db)):
    user = create_user(db = db, user = user)
    from fastapi.encoders import jsonable_encoder
    return reponse(data=jsonable_encoder(user, exclude=['hashed_password']))

Last updated