摘要: FastAPI 是一个基于 Python 3.7+ 的现代、快速(基于 Starlette 和 Pydantic)、标准(遵循 OpenAPI 和 JSON Schema 规范)的 Web 框架。 本专题存放关于Fastapi的学习笔记 阅读全文
posted @ 2023-10-01 15:52 Chimengmeng 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 【一】创建Jinja2引擎 # 必须模块 from fastapi import Request # 必须模块 from fastapi.templating import Jinja2Templates # 创建子路由 application = APIRouter() # 创建前端页面配置 te 阅读全文
posted @ 2023-10-01 15:33 Chimengmeng 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 【一】中间件 【1】中间件介绍 FastAPI 中间件是在处理请求和响应的过程中介入的组件,允许你在请求到达处理函数之前或响应离开处理函数之后执行一些逻辑。 中间件在 FastAPI 中起到非常灵活的作用,可以用于日志记录、身份验证、异常处理等。 【2】中间件的工作原理 (1)注册中间件 在 Fas 阅读全文
posted @ 2023-10-01 15:33 Chimengmeng 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 【一】大型项目结构树 coronavirus ├─static # 静态文件 ├─templates # 前端页面 ├─__init__.py # 初始化文件 ├─database.py # 数据库操作 ├─models.py # 数据库表模型类 ├─schemas.py # 响应体模型类 ├─cu 阅读全文
posted @ 2023-10-01 15:32 Chimengmeng 阅读(360) 评论(0) 推荐(0) 编辑
摘要: 【一】OAuth2.0的授权模式 授权码授权模式(Authorization Code Grant) 隐式授权模式(Implicit Grant) 密码授权模式(Resource Owner Password Credentials Grant) 客户端凭证授权模式(Client Credentia 阅读全文
posted @ 2023-10-01 15:32 Chimengmeng 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 【一】引入 【1】介绍 “依赖注入”是指在编程中,为保证代码成功运行,先导入或声明其所需要的 “依赖”,如子函数、数据库连接等 【2】优势 提高代码的复用率 共享数据库的连接 增强安全、认证和角色管理 【3】FastAPI的兼容性 所有的关系型数据库,支撑NoSQL数据库 第三方的包和API 认证和 阅读全文
posted @ 2023-10-01 15:32 Chimengmeng 阅读(30) 评论(0) 推荐(0) 编辑
摘要: 【一】表单参数 【1】定义视图 from fastapi import APIRouter, status, Form from pydantic import BaseModel, EmailStr from typing import Optional, Union, List app04 = 阅读全文
posted @ 2023-10-01 15:32 Chimengmeng 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 【一】自定义响应模型 【1】定义视图函数 from fastapi import APIRouter from pydantic import BaseModel, EmailStr from typing import Optional app04 = APIRouter() ### 响应模型 # 阅读全文
posted @ 2023-10-01 15:31 Chimengmeng 阅读(53) 评论(0) 推荐(0) 编辑
摘要: 【一】Cookie 操作 【1】定义视图函数 from fastapi import APIRouter, Path, Query,Cookie,Header from typing import Optional app03 = APIRouter() ## Cookie 和 Header 参数 阅读全文
posted @ 2023-10-01 15:31 Chimengmeng 阅读(61) 评论(0) 推荐(0) 编辑
摘要: 【一】说明 项目接上小结 【二】请求体和字段 from fastapi import APIRouter, Path, Query from pydantic import BaseModel, Field app03 = APIRouter() ## 请求体字段 class CityInfo(Ba 阅读全文
posted @ 2023-10-01 15:31 Chimengmeng 阅读(36) 评论(0) 推荐(0) 编辑
摘要: 【一】小项目构建 【1】文档结构树 projects ├─coronavirus ├─__init__.py ├─....py ├─turtorial ├─__init__.py ├─chapter03.py ├─chapter04.py ├─chapter05.py ├─chapter06.py 阅读全文
posted @ 2023-10-01 15:31 Chimengmeng 阅读(65) 评论(0) 推荐(0) 编辑
摘要: 【一】Fastapi引入 【1】构建基础的fastapi项目 from fastapi import FastAPI from typing import Optional from pydantic import BaseModel # 创建 fastapi 对象 app = FastAPI() 阅读全文
posted @ 2023-10-01 15:30 Chimengmeng 阅读(50) 评论(0) 推荐(0) 编辑
摘要: 【一】环境准备 【1】第三方包 requirements.txt aiofiles==0.6.0 atomicwrites==1.4.0 attrs==20.3.0 bcrypt==3.2.0 certifi==2020.12.5 cffi==1.14.4 chardet==4.0.0 click= 阅读全文
posted @ 2023-10-01 15:30 Chimengmeng 阅读(80) 评论(0) 推荐(0) 编辑
摘要: 【一】介绍 Data validation and settings management using python type annotations. 使用Python的类型注解来进行数据校验和settings管理 pydantic enforces type hints at runtime, 阅读全文
posted @ 2023-10-01 15:30 Chimengmeng 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 【一】介绍 Starlette 是个什么项目; IDE 开发时 Python 3.5+ 版本的 "type hints" 的好处:简短、直观和标准的 Python 类型声明; 介绍 Pydantic 包,FastAPI 项目的开发为什么要使用 Pydantic 【二】Starlette 【1】介绍 阅读全文
posted @ 2023-10-01 15:30 Chimengmeng 阅读(1077) 评论(0) 推荐(0) 编辑
摘要: 【一】为什么新秀 FastAPI 火成这样 介绍 FastAPI 有哪些突出特点,浏览官网文档中的 Feasures 一览 【二】FastAPI的突出特点 性能优越 开发效率 提升200%~300% 直接减少约40%的人为BUG 直观 易学易用 经简代码/代码重复率低 自带API交互文档,开发成果随 阅读全文
posted @ 2023-10-01 15:29 Chimengmeng 阅读(38) 评论(0) 推荐(0) 编辑
/* */