[FastAPI-14]pydantic多个请求体

Posted LeoShi2020

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[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

以上是关于[FastAPI-14]pydantic多个请求体的主要内容,如果未能解决你的问题,请参考以下文章