kinit/kinit-api
ktianc afa9110771 1. 更新:kinit-api:core/crud.py keys 查询多外键时需添加onclause属性
2. 修复:kinit-admin: form属性设置了ifshow无法设置值问题修复
3. 修复:kinit-admin:表格字段设置缓存问题修复
2023-02-08 11:11:28 +08:00
..
2022-12-04 21:42:59 +08:00
2023-01-30 15:34:24 +08:00
2022-10-18 19:53:35 +08:00
2022-09-16 12:32:51 +08:00
2023-01-30 15:47:05 +08:00
2022-09-16 12:32:51 +08:00
2022-10-11 08:49:15 +08:00
2022-12-04 21:42:59 +08:00
2023-01-30 15:47:05 +08:00
2022-12-04 21:42:59 +08:00
2023-01-30 15:34:24 +08:00

FastAPI 项目

fastapi 源代码:https://github.com/tiangolo/fastapi

fastapi 中文文档:https://fastapi.tiangolo.com/zh/

fastapi 更新说明:https://fastapi.tiangolo.com/zh/release-notes/

pydantic 官方文档:https://pydantic-docs.helpmanual.io/

pydantic 数据模型代码生成器官方文档 Json -> Pydantichttps://koxudaxi.github.io/datamodel-code-generator/

SQLAlchemy-Utilshttps://sqlalchemy-utils.readthedocs.io/en/latest/

alembic 中文文档:https://hellowac.github.io/alembic_doc/zh/_front_matter.html

Typer 官方文档:https://typer.tiangolo.com/

项目结构

使用的是仿照 Django 项目结构:

  • alembic数据库迁移配置目录
  • application主项目配置目录也存放了主路由文件
    • settings.py主项目配置文件
    • urls.py主路由文件
  • apps项目的app存放目录
  • core核心文件目录
    • database.py关系型数据库核心配置
    • exception.py异常处理
    • logger日志处理核心配置
    • middleware.py中间件核心配置
  • dbORM模型基类
  • logs日志目录
  • static静态资源存放目录
  • tests测试接口文件目录
  • utils封装的一些工具类目录
  • main.py主程序入口文件
  • alembic.ini数据库迁移配置文件

开发环境

开发语言Python 3.10

开发框架Fastapi 0.87.0

使用

source /opt/env/kinit-pro/bin/activate

# 安装依赖库
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/

# 第三方源:

1. 阿里源: https://mirrors.aliyun.com/pypi/simple/

数据初始化

# 项目根目录下执行,需提前创建好数据库
# 会自动将模型迁移到数据库,并生成初始化数据
python main.py init

运行启动

# 直接运行main文件
python main.py run

其他

在线文档地址(在配置文件里面设置路径或者关闭)

http://127.0.0.1:9000/docs

Git更新ignore文件直接修改gitignore是不会生效的需要先去掉已经托管的文件修改完成之后再重新添加并提交。

第一步:
git rm -r --cached .
去掉已经托管的文件

第二步:
修改自己的igonre文件内容

第三步:
git add .
git commit -m "clear cached"

执行数据库迁移命令(终端执行)

# 执行命令(生产环境):
python main.py migrate

# 执行命令(测试环境):
python main.py migrate --env dev

生成迁移文件后会在alembic迁移目录中的version目录中多个迁移文件