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

建设部网站职业资格证查询建设学院网站

建设部网站职业资格证查询,建设学院网站,洛阳市新区建设投资有限公司网站,怎么用自己主机做网站、上一篇 FastAPI 构建 API 高性能的 web 框架#xff08;一#xff09;是把LLM模型使用Fastapi的一些例子#xff0c;本篇简单来看一下FastAPI的一些细节。 有中文官方文档#xff1a;fastapi中文文档 假如你想将应用程序部署到生产环境#xff0c;你可能要执行以下操作一是把LLM模型使用Fastapi的一些例子本篇简单来看一下FastAPI的一些细节。 有中文官方文档fastapi中文文档 假如你想将应用程序部署到生产环境你可能要执行以下操作 pip install fastapi并且安装uvicorn来作为服务器 pip install uvicorn[standard]然后对你想使用的每个可选依赖项也执行相同的操作。 文章目录 1 基础使用1.1 单个值Query的使用1.2 多个参数1.3 请求参数 Field1.4 响应模型response_model1.5 请求文件UploadFile1.6 CORS跨域资源共享1.7 与SQL 通信 1 基础使用 参考https://fastapi.tiangolo.com/zh/tutorial/body-multiple-params/ 1.1 单个值Query的使用 from typing import Unionfrom fastapi import FastAPI, Queryapp FastAPI()app.get(/items/) async def read_items(q: Union[str, None] Query(defaultNone, max_length50)):results {items: [{item_id: Foo}, {item_id: Bar}]}if q:results.update({q: q})return results这里Union[str, None] 代表参数q可以是字符型也可以None不填Query用来更多的补充信息比如这个参数默认值是None最大长度50 1.2 多个参数 from typing import Annotatedfrom fastapi import FastAPI, Path from pydantic import BaseModelapp FastAPI()class Item(BaseModel): # 检查项不同key要遵从什么格式name: strdescription: str | None None # 字符或者None都可以默认Noneprice: floattax: float | None None # 数值或者None都可以默认Noneapp.put(/items/{item_id}) async def update_item(item_id: Annotated[int, Path(titleThe ID of the item to get, ge0, le1000)], # item_id是一个路径通过Annotated需要两次验证验证一是否是整数型验证二数值大小 大于等于0小于等于1000q: str | None None, item: Item | None None, # 格式遵从class Item类且默认为None ):results {item_id: item_id}if q:results.update({q: q})if item:results.update({item: item})return results1.3 请求参数 Field pydantic中比较常见 from typing import Annotatedfrom fastapi import Body, FastAPI from pydantic import BaseModel, Fieldapp FastAPI()class Item(BaseModel):name: strdescription: str | None Field(defaultNone, titleThe description of the item, max_length300)# 跟Query比较相似设置默认title解释最大长度300price: float Field(gt0, descriptionThe price must be greater than zero)# price大于0且是float形式tax: float | None Noneapp.put(/items/{item_id}) async def update_item(item_id: int, item: Annotated[Item, Body(embedTrue)]):results {item_id: item_id, item: item}return results1.4 响应模型response_model 参考https://fastapi.tiangolo.com/zh/tutorial/response-model/ from typing import Anyfrom fastapi import FastAPI from pydantic import BaseModel, EmailStrapp FastAPI()class UserIn(BaseModel):username: strpassword: stremail: EmailStrfull_name: str | None Noneclass UserOut(BaseModel):username: stremail: EmailStrfull_name: str | None Noneapp.post(/user/, response_modelUserOut) async def create_user(user: UserIn) - Any:return userresponse_model是控制输出的内容按照规定的格式输出作用概括为 将输出数据转换为其声明的类型。校验数据。在 OpenAPI 的路径操作中为响应添加一个 JSON Schema。并在自动生成文档系统中使用。 1.5 请求文件UploadFile https://fastapi.tiangolo.com/zh/tutorial/request-files/ from fastapi import FastAPI, File, UploadFileapp FastAPI()app.post(/files/) async def create_file(file: bytes File()):return {file_size: len(file)}app.post(/uploadfile/) async def create_upload_file(file: UploadFile):return {filename: file.filename}UploadFile 与 bytes 相比有更多优势 这种方式更适于处理图像、视频、二进制文件等大型文件好处是不会占用所有内存可获取上传文件的元数据 1.6 CORS跨域资源共享 https://fastapi.tiangolo.com/zh/tutorial/cors/ 你可以在 FastAPI 应用中使用 CORSMiddleware 来配置它。 导入 CORSMiddleware。创建一个允许的源列表由字符串组成。将其作为「中间件」添加到你的 FastAPI 应用中。 from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddlewareapp FastAPI()origins [http://localhost.tiangolo.com,https://localhost.tiangolo.com,http://localhost,http://localhost:8080, ]app.add_middleware(CORSMiddleware,allow_originsorigins,allow_credentialsTrue,allow_methods[*],allow_headers[*], )app.get(/) async def main():return {message: Hello World}allow_origins - 一个允许跨域请求的源列表。例如 [‘https://example.org’, ‘https://www.example.org’]。你可以使用 [‘*’] 允许任何源。 1.7 与SQL 通信 https://fastapi.tiangolo.com/zh/tutorial/sql-databases/ FastAPI可与任何数据库在任何样式的库中一起与 数据库进行通信。
http://www.hkea.cn/news/14397891/

相关文章:

  • 哈尔滨队网站网页美工小程序登录后台
  • 烟台制作网站做外贸方面的网站
  • 婚纱摄影团购网站模板中国互联网站建设中心
  • 做网站找投资人开网店需要多少钱?
  • 做网站排名步骤招聘小程序怎么制作
  • 做网站做什么赚钱静态网站做毕业设计
  • 贵阳网站建设是什么个人养老保险一年交多少钱
  • 负责网站开发的岗位手机网站大全观看
  • 黄浦品牌网站建设温州做网站建设哪家好
  • 长寿网站制作营销传播方式有哪些
  • 网站建设报告书快照网站
  • 免备案网站空间购买百度信息流是什么
  • html静态页面怎么放在网站上如何选网站空间
  • 兰州北山生态建设局网站网站修改图片怎么做
  • 南通网络公司网站值得关注的网站
  • 平面设计招聘唐山百度优化排名
  • 开通建立企业网站聊城九洲建设有限公司网站
  • 解析视频的网站怎么做做视频链接哪个网站好
  • 网站建设需求原型最近最新在线观看免费高清完整版
  • 郑州人才网站ppt模板免费下载素材库
  • 金华市建设银行网站代理公司注册合同范本
  • 什么叫网站集约化建设南宁做网站找哪家公司
  • 订阅号怎么做微网站河北搜索引擎推广价格
  • ftp上传后没有网站北京公司注册流程及需要的材料
  • 自考网站建设与管理数据库设计对网站开发的影响
  • 盐城网站建设有限公司网络建设需求
  • jsp网站开发软件哪个好宠物网站建设的目的
  • 永康住房和城乡建设部网站深圳网站建设 设计首选
  • 镇江网站建设咨询公司重名 做网站
  • 沧州网站设计公司价格推广网站免费