我的 FastAPI 调用未以正确的模型格式返回数据Response。它以数据库模型格式返回数据。
我的数据库模型:
class cat(DBConnect.Base):
__tablename__ = 'category'
__table_args__ = {"schema": SCHEMA}
cat_id = Column('cat_id',UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
cat_desc = Column('cat_desc', TEXT, nullable=True)
cat_h__l_name = Column('cat_h_l_name', TEXT, nullable=True)
Run Code Online (Sandbox Code Playgroud)
我的 Pydantic 模型:
class CamelModel(BaseModel):
class config:
alias_generator = to_camel
allow_population_by_field_name = True
class cat(CamelModel):
cat_id =Field(alais='CatID', readonly=True)
cat_description =Field(alias='CatDescription')
cat_h__l_name = Field(alias='CatName')
class config:
orm_mode= True
Run Code Online (Sandbox Code Playgroud)
我的 API 调用:
@router.patch('/cat/{id}/', response_model = 'cat')
def update_cat(response= Response, params: updatecat = Depends(updatecat)):
response_obj = { resonse_code: status.HTTP_200_OK,
response_obj : {}
} …Run Code Online (Sandbox Code Playgroud)