当前位置: 首页 > 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://wiki.neutronadmin.com/news/267253/

相关文章:

  • 网站seo多少钱什么网站建设效果好
  • 东莞市建设工程检测中心网站小程序搭建系统
  • 网站多语言包制作图片的软件ppt
  • 素材网站设计模板ppth5怎么制作
  • 网站建设服务商有哪些如何设计网络
  • 建立大型网站wordpress大前端d84.1
  • 推网站建设话术哪些网站是做货源的
  • 淘宝客导购网站怎么建设千锋前端培训班
  • 做不了大流量网站建设公司内网网站的意义
  • 电子商务网站建设asp网址ip地址查询工具
  • 美工常用找素材网站百度网站优化升上去
  • 辽宁建设网站首页查营业执照怎么查询
  • app程序开发定制网站优化难吗
  • 网站 掌握怎么做多语言网站
  • 网站制作方案设计台州制作网站软件
  • 企业网站建设广州蓝色风格企业网站模板
  • 移动端手机网站模板下载哪家企业建设网站好
  • 茶叶网站的建设策划书wordpress5.0启多站点
  • 网站规划与建设需求分析淘宝网现状 网站建设
  • 网站文章页的排名怎么做泰和县城乡建设局网站
  • 保险网站有哪些保险网站上海暂停娱乐场所营业通知
  • 深圳电子商务网站开发做企业网站报价
  • 哈尔滨的网站建设公司哪家好做网站的开源代码
  • asp网站开发环境cpu如何检查网站是否做cdn加速
  • 开发商建设审批网站项目管理pmp
  • 物联网平台网站开发考试网站模版
  • 网站数据库怎么建自己在线制作logo免费图片
  • 公司的网站建设费会计分录wordpress 图片浏览器
  • 网站建设下什么费用织梦做的网站怎么传到网上
  • 怎样用jsp做网站登录外贸网站模板免费下载