Answer the question
In order to leave comments, you need to log in
fast API. How to add data processing to the text field that came in from pydantic import BaseModel?
from pydantic import BaseModel
class Request(BaseModel):
text: str
client_id: str
Answer the question
In order to leave comments, you need to log in
the simplest is to use a validator
from pydantic import BaseModel, validator
class Request(BaseModel):
text: str
client_id: str
@validator('text')
def str_to_lower(cls, text: str):
return text.lower()
print(Request(text='Lower To Lower', client_id='Client'))
text='lower to lower' client_id='Client'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question