首页 > 其他分享 >[FastAPI-22]响应模型-response_model

[FastAPI-22]响应模型-response_model

时间:2023-03-25 12:57:29浏览次数:41  
标签:22 FastAPI app str import model response

import typing

from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse
from pydantic import BaseModel

app = FastAPI()

'''
响应模型
swagger Example显示
'''


class BaseUser(BaseModel):
    username: str
    email : str

class UserIn(BaseUser):
    password : str
    re_password : str

class UserOut(BaseUser):
    pass

@app.post("/register",response_model=UserOut)
def register(user : UserIn):
    # 注册用户的操作
    return user

@app.post("/demo",response_model=typing.Dict[str,str])
# 字段类型转换
def dmeo():
    return {
        "name":"Tom",
        "age":18
    }

标签:22,FastAPI,app,str,import,model,response
From: https://www.cnblogs.com/leoshi/p/17254533.html

相关文章

  • [FastAPI-21]响应体
    fromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()classUser(BaseModel):u......
  • Modelsim SE 下载安装、注册详细教程
    声明:原博客为https://blog.csdn.net/ssj925319/article/details/115353790此文仅为记录安装过程,方便日后查看一、ModelsimSE下载及安装百度网盘下载链接:https://pan......
  • iview Input 必填不能未空 不能输入空格 v-model.trim required: true
    iviewInput必填不能未空不能输入空格v-model.trimrequired:true需求测试在验证必填的时候,会输入一个空格,本着空格不算内容的原则,会提一个bug解决方案v-model.trim数......
  • iview Input 必填不能未空 不能输入空格 v-model.trim required: true
    iviewInput必填不能未空不能输入空格v-model.trimrequired:true需求测试在验证必填的时候,会输入一个空格,本着空格不算内容的原则,会提一个bug解决方案v-model.trim数......
  • [FastAPI-20]设置响应头
    fromfastapiimportFastAPI,Responsefromfastapi.responsesimportJSONResponsefrompydanticimportBaseModelapp=FastAPI()classUser(BaseModel):u......
  • [省选联考 2022] 卡牌 解题报告
    作为一道著名题,当然是有必要改一改的。本文会介绍卡牌的两种做法:容斥和FWT。下文将默认读者已经清晰地阅读了题目,没有漏过任何性质和条件。容斥这个做法应该是比较好想......
  • 【专题】2022中国新能源汽车内容生态趋势洞察报告PDF合集分享(附原数据表)
    报告链接:http://tecdat.cn/?p=31970原文出处:拓端数据公众号《报告》以关注新能源汽车内容的网络用户和中国新能源汽车企业为研究对象,选择了与新能源汽车有关的网络内容(图......
  • ubuntu 22.04 dell 3571指纹识别
    指纹识别在linux能不能用看主要看有没有相关的驱动。3571带的指纹是ID0a5c:5843BroadcomCorp.58200,参照文档进行安装,有一点与文档不同,驱动目录需要切换到jammy分支。以......
  • AC-220V零点检测///京鸿通信科技(深圳)有限公司//15507589165
    AC-220V零点检测一般系统结构都是如下图所示。 过零检测主要有三个作用:(1)可控硅触发。通过检测AC220V过零点,可以调节可控硅的导通时间,从而进行电压控制等。(2)继电......
  • 225. 用队列实现栈
    请你仅使用两个队列实现一个后入先出(LIFO)的栈,并支持普通栈的全部四种操作(push、top、pop和empty)。实现MyStack类:voidpush(intx)将元素x压入栈顶。intpop()移......