当前位置: 首页 > news >正文

网站文化制度建设phpcms v9企业网站模板:蓝色电子科技公司网站模板

网站文化制度建设,phpcms v9企业网站模板:蓝色电子科技公司网站模板,网页设计规范要求,什么网站做软文文章目录1. 混合使用 Path、Query 和请求体参数2. 多个请求体参数3. 请求体中的单一值4. 多个请求体参数和查询参数5. 嵌入单个请求体参数6. 字段7. 嵌套模型7.1 List 字段7.2 子模型作为类型8. 特殊类型校验9. 带有一组子模型的属性10. 任意 dict 构成的请求体learn from http… 文章目录1. 混合使用 Path、Query 和请求体参数2. 多个请求体参数3. 请求体中的单一值4. 多个请求体参数和查询参数5. 嵌入单个请求体参数6. 字段7. 嵌套模型7.1 List 字段7.2 子模型作为类型8. 特殊类型校验9. 带有一组子模型的属性10. 任意 dict 构成的请求体learn from https://fastapi.tiangolo.com/zh/tutorial/body-multiple-params/ 1. 混合使用 Path、Query 和请求体参数 from fastapi import FastAPI, Path from typing import Optional from pydantic import BaseModel app FastAPI()class Item1(BaseModel):name: strprice: floatdescription: Optional[str] Nonetax: Optional[float]app.put(/items/{item_id}) async def update_item(*,item_id: int Path(..., titleid of item to get, ge0, le1000),q: Optional[str] None,item: Optional[Item1] None, ):res {item_id: item_id}if q:res.update({q: q})if item:res.update({item: item})return res2. 多个请求体参数 from pydantic import BaseModelclass Item(BaseModel):name: strprice: floatdescription: Optional[str] Nonetax: Optional[float] class User(BaseModel):username: strfull_name: Optional[str] Noneapp.put(/items/{item_id}) async def update_item(item_id: int, item: Item, user: User):res {item_id : item_id, item : item, user: user}return res使用 参数名称 最为 key 的 字典传入 3. 请求体中的单一值 传参时varname : type Body(...)如果不这么写会被作为查询参数 ?varnamexxx from fastapi import Bodyclass Item(BaseModel):name: strprice: floatdescription: Optional[str] Nonetax: Optional[float] class User(BaseModel):username: strfull_name: Optional[str] Noneapp.put(/items/{item_id}) async def update_item(item_id: int, item: Item, user: User, importance : int Body(...)):res {item_id : item_id, item : item, user: user}return res现在可以写在请求体内 4. 多个请求体参数和查询参数 由于默认情况下单一值被解释为查询参数因此你不必显式地添加 Query你可以仅执行操作q: str None 5. 嵌入单个请求体参数 如果你只有一个请求体参数 app.put(/items/{item_id}) async def update_item(item_id: int, item: Item):res {item_id : item_id, item : item}return res你的请求体需要写成如下形式 如果你想写成 带 key 的 json 形式添加一个传入参数 embeditem: Item Body(..., embedTrue) 6. 字段 可以使用 Pydantic 的 Field 在 Pydantic 模型内部声明校验和元数据 from fastapi import FastAPI, Path, Body from typing import Optional from pydantic import BaseModel, Field app FastAPI()class Item(BaseModel):name: strprice: float Field(..., gt0, descriptionprice must be greater than 0)description: Optional[str] Field(None, titledescription of item, max_length30)tax: Optional[float] Noneapp.put(/items/{item_id}) async def update_item(item_id: int, item: Item Body(..., embedTrue)):res {item_id : item_id, item : item}return resField 的工作方式和 Query、Path 和 Body 相同包括它们的参数等等也完全相同 注意from pydantic import Field 7. 嵌套模型 7.1 List 字段 将一个属性定义为拥有子元素的类型如 list class Item(BaseModel):name: strprice: float Field(..., gt0, descriptionprice must be greater than 0)description: Optional[str] Field(None, titledescription of item, max_length30)tax: Optional[float] Nonetags: list [] # 没有声明元素类型具有子类型的 Listfrom typing import List tags: List[str] []7.2 子模型作为类型 from fastapi import FastAPI, Path, Body from typing import Optional, List, Set from pydantic import BaseModel, Field app FastAPI()class Image(BaseModel):url:strname: strclass Item(BaseModel):name: strprice: float Field(..., gt0, descriptionprice must be greater than 0)description: Optional[str] Field(None, titledescription of item, max_length30)tax: Optional[float] Nonetags: Set[str] []image: Optional[Image] Noneapp.put(/items/{item_id}) async def update_item(item_id: int, item: Item Body(..., embedTrue)):res {item_id : item_id, item : item}return res8. 特殊类型校验 HttpUrl检查是不是有效的 URL from pydantic import BaseModel, Field, HttpUrl app FastAPI()class Image(BaseModel):url: HttpUrlname: str则上面的输入应改的地方 url:http://www.michael.com,否则不是有效的 URL 9. 带有一组子模型的属性 更改为 image: Optional[List[Image]] None 输入需要改为 app.post(/images/multiple/) async def create_multiple_images(images: List[Image]):return images10. 任意 dict 构成的请求体 from typing import Optional, List, Set, Dict app.post(/index-weights/) async def create_index_weights(weights: Dict[int, float]): # key 为 int value 为浮点return weights请记住 JSON 仅支持将 str 作为键。 但是 Pydantic 具有自动转换数据的功能。
http://www.yutouwan.com/news/267253/

相关文章:

  • 风雨同舟网站建设广告设计与制作专业技能
  • 网站制作语言百能网是哪家公司做的网站
  • 做外贸网站报价单大气的企业网站
  • 青岛建设银行股份有限公司网站网站空间域名免费
  • 公司网站制作效果数字化档案馆及网站的建设
  • 百度站长平台网站改版工具网站的维护步骤
  • 网站建设结课总结品牌建设对策
  • 网站入股云建站小程序开发平台网站推荐
  • 网站设置在设备之间共享什么意思另类小说 Wordpress
  • DZ做的网站做网站一般什么问题
  • 受欢迎的大连网站建设互联网公司排名2024
  • 受欢迎的句容网站建设做网站原创要多少钱
  • 河北高端网站设计公司南昌p2p网站建设
  • 网站空间2G一年多少钱去掉wordpress.org
  • 企业网站建设费用怎么核算06年可以做相册视频的网站
  • 企业做企业网站的好处福步外贸网
  • 源码网站git株洲网站建设服务公司
  • 域名访问网站下个人建站提供软件下载
  • 上海公司网站建设方案网址搜索栏
  • 手机网站开发学习1688官网电脑版
  • 大型营销型网站建设宜昌最新消息今天
  • 建设银行信用卡网站查询关于公司建网站
  • 做网站如何让用户注册开发公司成本如何管控
  • 谷歌外贸网站推广wordpress 多用户博客
  • 怎么创建自己的网址已收录的网站不好优化
  • 看过的网站做记号网站开发技术学习
  • 支付宝网站开发黄冈网站推广收费标准
  • 网站关键词优化合同网站域名注册免费
  • 精品网站建设价格做网站的开发环境
  • 福建闽东建设网站怎么给制作网站谷歌地图