Pydantic v1 vs Pydantic v2 FastAPI is now compatible with both Pydantic v1 and Pydantic v2. You need to take care of methods name changes according to usage of Pydantic. Three of them are: .dict() function is now renamed to .model_dump() schema_extra frunction within a Config class is now renamed to json_schema_extra Optional variables need a =None example: id: Optional[int]=None Code and result: Get request code books3.py class Book : id : int title : str author : str description : str rating : int def __init__ ( self , id : int , title : str , author : str , description : str , rating : int ): self . id = id self . title = title self . author = author self . description = description self . rating = rating main.py from fastapi import FastAPI fr...
Comments
Post a Comment