摘要: HttpBasic基本认证 from fastapi import FastAPI, Depends from fastapi.security import HTTPBasic, HTTPBasicCredentials from fastapi.exceptions import HTTPExc 阅读全文
posted @ 2024-02-28 19:09 我在路上回头看 阅读(80) 评论(0) 推荐(0) 编辑
摘要: aioredis official website Install pip install aioredis Connect to redis from fastapi import FastAPI import aioredis app = FastAPI() @app.on_event('sta 阅读全文
posted @ 2024-02-28 19:04 我在路上回头看 阅读(581) 评论(0) 推荐(0) 编辑
摘要: jwt认证 1.头部Header,主要是对jwt元数据的描述 { 'alg': 'HS256', 'typ': 'JWT' } 2.载荷playload,主要包含jwt信息需要传递的主体数据 { 'iss': 'jack', # 由jwt签发 'sub': 'jack', # 该jwt面向的用户组, 阅读全文
posted @ 2024-02-28 19:00 我在路上回头看 阅读(271) 评论(0) 推荐(0) 编辑
摘要: from typing import Optional, Tuple from fastapi import FastAPI, Request from pydantic import BaseModel # 通过starlette.authentication导入AuthenticationBac 阅读全文
posted @ 2024-02-28 18:42 我在路上回头看 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 官网 sqlmodel 安装 # 安装sqlmodel会自动安装pydantic和sqlalchemy pip install sqlmodel 使用 # 步骤1,创建sqlmodel引擎 from sqlmodel import create_engine # driver://用户名:密码@ip 阅读全文
posted @ 2024-02-28 18:37 我在路上回头看 阅读(1269) 评论(0) 推荐(0) 编辑
摘要: 应用启动和关闭事件(旧版本) 事件处理程序,在应用程序启动之前和关闭期间执行。每次uvicorn和hypercorn服务器重启加载时都会激活这些事件 app = FastAPI() # 启动事件 @app.on_event("startup") async def initialize(reques 阅读全文
posted @ 2024-02-28 18:14 我在路上回头看 阅读(224) 评论(0) 推荐(0) 编辑
摘要: 依赖包 pip install python-dotenv 使用 #.env文件 ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" # config.py from pydantic_settings import BaseSet 阅读全文
posted @ 2024-02-28 18:09 我在路上回头看 阅读(162) 评论(0) 推荐(0) 编辑
摘要: 函数式依赖项 from fastapi import FastAPI from fastapi import Query, Depends from fastapi.exceptions import HTTPException app = FastAPI() def username_check( 阅读全文
posted @ 2024-02-28 18:07 我在路上回头看 阅读(88) 评论(0) 推荐(0) 编辑
摘要: 注:后台任务应附加到响应中,并且仅在发送响应后运行 用于将单个后台任务添加到响应中 from fastapi import FastAPI from fastapi.responses import JSONResponse from starlette.background import Back 阅读全文
posted @ 2024-02-28 17:58 我在路上回头看 阅读(109) 评论(0) 推荐(0) 编辑
摘要: 中间件介绍 中间件是一个函数,它在每个请求被特定的路径操作处理之前 ,以及在每个响应返回之前工作 装饰器版中间件 1.必须使用装饰器@app.middleware("http"),且middleware_type必须为http 2.中间件参数:request, call_next,且call_nex 阅读全文
posted @ 2024-02-28 17:56 我在路上回头看 阅读(521) 评论(0) 推荐(0) 编辑