[FastAPI-14]pydantic多个请求体

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}
posted @ 2023-03-23 23:46  LeoShi2020  阅读(29)  评论(0编辑  收藏  举报