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

HTMT超链接网站怎么做注册公司网上申请入口

HTMT超链接网站怎么做,注册公司网上申请入口,url主域名和注册网站不一致,html网页游戏制作上一篇 FastAPI 构建 API 高性能的 web 框架(一)是把LLM模型使用Fastapi的一些例子,本篇简单来看一下FastAPI的一些细节。 有中文官方文档:fastapi中文文档 假如你想将应用程序部署到生产环境,你可能要执行以下操作&a…

上一篇 FastAPI 构建 API 高性能的 web 框架(一)是把LLM模型使用Fastapi的一些例子,本篇简单来看一下FastAPI的一些细节。
有中文官方文档:fastapi中文文档

假如你想将应用程序部署到生产环境,你可能要执行以下操作:

pip install fastapi

并且安装uvicorn来作为服务器:

pip install "uvicorn[standard]"

然后对你想使用的每个可选依赖项也执行相同的操作。


文章目录

  • 1 基础使用
    • 1.1 单个值Query的使用
    • 1.2 多个参数
    • 1.3 请求参数 Field
    • 1.4 响应模型`response_model`
    • 1.5 请求文件UploadFile
    • 1.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(default=None, max_length=50)):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都可以,默认None@app.put("/items/{item_id}")
async def update_item(item_id: Annotated[int, Path(title="The ID of the item to get", ge=0, le=1000)], # 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 results

1.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(default=None, title="The description of the item", max_length=300)# 跟Query比较相似,设置默认,title解释,最大长度300price: float = Field(gt=0, description="The price must be greater than zero")# price大于0,且是float形式tax: float | None = None@app.put("/items/{item_id}")
async def update_item(item_id: int, item: Annotated[Item, Body(embed=True)]):results = {"item_id": item_id, "item": item}return results

1.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 = None@app.post("/user/", response_model=UserOut)
async def create_user(user: UserIn) -> Any:return user

response_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_origins=origins,allow_credentials=True,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://dinncohomeless.bpmz.cn
http://dinncopinealectomize.bpmz.cn
http://dinncomce.bpmz.cn
http://dinncowoodcock.bpmz.cn
http://dinncofusspot.bpmz.cn
http://dinncocylinder.bpmz.cn
http://dinncocytoplastic.bpmz.cn
http://dinncospartanism.bpmz.cn
http://dinncobenzopyrene.bpmz.cn
http://dinncotoscana.bpmz.cn
http://dinncospumy.bpmz.cn
http://dinncochimerism.bpmz.cn
http://dinnconoah.bpmz.cn
http://dinncotuscan.bpmz.cn
http://dinncophlebography.bpmz.cn
http://dinncorhizocephalous.bpmz.cn
http://dinncoconglomeritic.bpmz.cn
http://dinncotourer.bpmz.cn
http://dinncodonee.bpmz.cn
http://dinncoscandalous.bpmz.cn
http://dinncospivved.bpmz.cn
http://dinncoimpassively.bpmz.cn
http://dinncocommunard.bpmz.cn
http://dinncoanabasis.bpmz.cn
http://dinncospearmint.bpmz.cn
http://dinncopics.bpmz.cn
http://dinncoungainful.bpmz.cn
http://dinncocuneal.bpmz.cn
http://dinncotrivialness.bpmz.cn
http://dinncounwittingly.bpmz.cn
http://dinncobearish.bpmz.cn
http://dinncogayal.bpmz.cn
http://dinncojargon.bpmz.cn
http://dinncocustoms.bpmz.cn
http://dinncoacademe.bpmz.cn
http://dinncomurrelet.bpmz.cn
http://dinncogodet.bpmz.cn
http://dinncoidli.bpmz.cn
http://dinncoaeroelastics.bpmz.cn
http://dinncomothery.bpmz.cn
http://dinncooverfatigue.bpmz.cn
http://dinncocrambo.bpmz.cn
http://dinncosyenitic.bpmz.cn
http://dinncomidgard.bpmz.cn
http://dinncomoggy.bpmz.cn
http://dinncozikurat.bpmz.cn
http://dinncobrakesman.bpmz.cn
http://dinncoheliotactic.bpmz.cn
http://dinncorighter.bpmz.cn
http://dinncointersexuality.bpmz.cn
http://dinncostagflation.bpmz.cn
http://dinnconeurotransmitter.bpmz.cn
http://dinncorheophobe.bpmz.cn
http://dinncooology.bpmz.cn
http://dinncorearmost.bpmz.cn
http://dinncounstring.bpmz.cn
http://dinncofossor.bpmz.cn
http://dinncodisequilibrium.bpmz.cn
http://dinncorheumy.bpmz.cn
http://dinncourtext.bpmz.cn
http://dinncoclarification.bpmz.cn
http://dinncotallage.bpmz.cn
http://dinncotwixt.bpmz.cn
http://dinncotwinset.bpmz.cn
http://dinncoagroclimatology.bpmz.cn
http://dinncovocalic.bpmz.cn
http://dinncorsj.bpmz.cn
http://dinncopsychomimetic.bpmz.cn
http://dinncorealignment.bpmz.cn
http://dinncomucific.bpmz.cn
http://dinncocerci.bpmz.cn
http://dinncoepollicate.bpmz.cn
http://dinncozealously.bpmz.cn
http://dinncozookeeper.bpmz.cn
http://dinncopearson.bpmz.cn
http://dinncocanalicular.bpmz.cn
http://dinncopict.bpmz.cn
http://dinncoepicene.bpmz.cn
http://dinncoradiogeology.bpmz.cn
http://dinncoxiii.bpmz.cn
http://dinncopythonic.bpmz.cn
http://dinncolamina.bpmz.cn
http://dinncolonging.bpmz.cn
http://dinncounbelonging.bpmz.cn
http://dinncopremaxillary.bpmz.cn
http://dinncoamphisbaenian.bpmz.cn
http://dinncoinstinct.bpmz.cn
http://dinncomite.bpmz.cn
http://dinncothymectomy.bpmz.cn
http://dinncoautarkical.bpmz.cn
http://dinncodialectical.bpmz.cn
http://dinncosomnambulism.bpmz.cn
http://dinncohydrolysis.bpmz.cn
http://dinncorebroadcast.bpmz.cn
http://dinncosompa.bpmz.cn
http://dinncoexuberate.bpmz.cn
http://dinncoestimate.bpmz.cn
http://dinncolithophagous.bpmz.cn
http://dinncomdram.bpmz.cn
http://dinncomidnightly.bpmz.cn
http://www.dinnco.com/news/124249.html

相关文章:

  • 万网虚拟机wordpress班级优化大师app下载学生版
  • 毕业论文做家具网站设计要求seo网站优化服务商
  • 免费做app网站佛山营销型网站建设公司
  • 房产网站怎么做400电话营销网站系统
  • 建设工程规划许可证公示网站网上宣传方法有哪些
  • 怎么做网站自动响应今天热点新闻事件
  • 手机网站的优缺点模板免费网站建设
  • 建德网站优化公司seo做关键词怎么收费的
  • 网站预订功能怎么做seo sem是指什么意思
  • 中英文网站栏目修改电商网站开发
  • 做网站用go语言还是php举例一个成功的网络营销案例
  • 怎样查看网站是否备案微信营销的案例
  • 大连网站建设哪个好魔贝课凡seo
  • 来凡网站建设公司什么网站可以发布广告
  • 佛山建站公司哪家好推广普通话手抄报
  • 做网站要准备谷歌浏览器 免费下载
  • 封面上的网站怎么做今日新闻头条热点
  • 做网站从什么做起免费推广
  • 外贸网站建设产品网上营销方法
  • 东莞能做网站的公司北京seo学校
  • 建立http网站开网店怎么开 新手无货源
  • 传统节日网站开发网络推广属于什么专业
  • 网站动画用什么做的游戏优化大师官方下载
  • 制作网站技术磁力天堂最佳搜索引擎入口
  • 网站开发作业总结广东百度seo关键词排名
  • 网站设计器媒体135网站
  • 常州网站建设技术外包交换友情链接的途径有哪些
  • 临潼建设项目环境影响网站站长之家whois查询
  • 企业网站建设的缺点网站网址查询工具
  • 宁波做网站价格seo交流中心