from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
'''
多个请求体
{
"user": {
"username": "string",
"password": "string"
},
"item": {
"name": "string",
"description": "string",
"price": 0,
"tax": 0
}
}
'''
class User(BaseModel):
username: str
password: str
class Item(BaseModel):
name: str
description: str
price: float
tax: float
@app.post("/login")
def login(user: User, item: Item):
return {"user":user,
"item":item}
标签:14,FastAPI,item,user,str,pydantic,string
From: https://www.cnblogs.com/leoshi/p/17249953.html