@app04.post( "/response_model/attributes", #response_model=UserOut, #response_model=Union[UserIn, UserOut]#取并集 #response_model=List[UserOut] #也可以用列表,响应多个模型类return [user,user] response_model_include=["username", "email"] #当响应字段太多时指定包含或排除哪些字段 # response_model_exclude={"mobile"} ) async def response_model_attributes(user: UserIn): #del user.password #Union[UserIn, UserOut]后,删除password属性 return user
我试了好几次,,返回都是返回了全部字段;
把[],改成{}:
response_model_include={'username','mobile'},
还有。model不能少,不然也不行:
esponse_model=UserOut,
response_model_exclude_unset=True