摘要: 一,代码 jwt功能模块和用户登录的两个依赖项: import hashlib from datetime import datetime, timedelta, timezone from typing import Optional from fastapi import FastAPI, De 阅读全文
posted @ 2026-06-29 20:09 刘宏缔的架构森林 阅读(1) 评论(0) 推荐(0)
摘要: 一,代码: plugin: from starlette.requests import Request from starlette_context.plugins import Plugin class PythonRequestPlugin(Plugin): # 1. 定义在 context 阅读全文
posted @ 2026-06-29 20:09 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)
摘要: 一,安装第三方库 库地址: https://pypi.org/project/starlette-context/ 安装: $ pip install starlette-context 二,代码 1,登录后把用户信息保存到上下文中 from starlette_context.plugins im 阅读全文
posted @ 2026-06-29 20:09 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)
摘要: 一,代码 说明:只针对admin管理后台,不影响其他子应用如api basic的代码 # app/core/adminbasic.py import secrets from fastapi import FastAPI, Depends, HTTPException, status from fa 阅读全文
posted @ 2026-06-29 20:09 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)
摘要: 在生产环境中,不建议直接运行 uvicorn main:app,因为一旦程序崩溃不会自动重启,且无法利用多核 CPU。所以我们使用 Gunicorn 来管理 Uvicorn。 在 FastAPI 项目的线上部署中,Gunicorn 和 Supervisor 扮演着完全不同的角色,它们的分工极其明确。 阅读全文
posted @ 2026-06-25 23:12 刘宏缔的架构森林 阅读(9) 评论(0) 推荐(0)
摘要: 一,安装用到的第三方库,并初始化 $ pip install alembic 初始化,注意指定异步模板: alembic init -t async alembic 因为我们使用的是异步驱动(aiomysql),初始化时必须指定 async 异步模板:执行后,项目根目录下会多出 alembic.in 阅读全文
posted @ 2026-06-25 16:28 刘宏缔的架构森林 阅读(5) 评论(0) 推荐(0)
摘要: 一,问题和原因 alembic revision --autogenerate -m "create user table" 这个命令执行后没有效果,没有找到数据表,原因是? Alembic 的核心配置文件是 migrations/env.py(或 alembic/env.py)。你需要确保在这里显 阅读全文
posted @ 2026-06-25 16:19 刘宏缔的架构森林 阅读(6) 评论(0) 推荐(0)
摘要: 一, Alembic和flask db的关系 FastAPI 本身并没有默认的数据库迁移库,因为它是一个微框架(Microframework),不绑定任何特定的 ORM 或数据库工具。但在实际开发中,FastAPI 社区官方推荐且最广泛使用的数据库迁移库是 Alembic。 它与 flask db( 阅读全文
posted @ 2026-06-24 22:30 刘宏缔的架构森林 阅读(5) 评论(0) 推荐(0)
摘要: 一、 Postman 中两种提交方式的本质区别 1. Params(查询参数 / Query Parameters) 传输位置:拼接在 URL 链接 后面。例如你在 Params 输入 id=10,Postman 实际发出的请求 URL 会变成:http://api.com。 数据限制:只能传输纯文 阅读全文
posted @ 2026-06-24 22:14 刘宏缔的架构森林 阅读(5) 评论(0) 推荐(0)
摘要: 一,官方文档地址: https://pydantic.dev/docs/validation/latest/api/pydantic/fields/ 安装用到的库:校验邮箱时用到 $ pip install 'pydantic[email]' 二,代码的例子: # 1. 定义校验规则 # ^[\u4 阅读全文
posted @ 2026-06-24 21:01 刘宏缔的架构森林 阅读(2) 评论(0) 推荐(0)