介绍:
Kinit 是一套开箱即用的中后台解决方案,可以作为新项目的启动模版,前后端分离架构,开箱即用,在线例子:https://kinit.ktianc.top/login。
1. 后端Api应用安装及初始化
# 获取
git clone https://gitee.com/ktianc/kinit.git
# 安装依赖
cd kinit-api
pip3 install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
# 全局环境配置
文件: application/settings.py
DEBUG = True
DEMO = False
# 子环境配置(数据库, 第三方)
文件:application/config/development.py or production.py
# 数据库模型映射配置(也需设置数据库用密)
文件:alembic.ini
# 初始化数据库数据:
# (生产环境)
python3 main.py init
# (开发环境)
python3 main.py init --env dev
# 启动
# 进入项目根目录下执行
python3 main.py run
默认账号:15020221010 密码:kinit2022
2. 数据库迁移或维护
- 用的是alembic工具 Welcome to Alembic’s documentation! — Alembic 1.13.1 documentation
# 创建一个新的迁移
alembic --name dev revision -m "add age column"
编辑迁移文件
def upgrade():
op.add_column('users', sa.Column('age', sa.Integer))
def downgrade():
op.drop_column('users', 'age')
命令执行
alembic upgrade head
# 回滚上一版本
alembic downgrade -1
3. VS Code中的项目launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name":"Run Api",
"type":"python",
"request":"launch",
"program":"kinit-api/main.py",
"args":["run"],
"console":"integratedTerminal",
"justMyCode":true
},
{
"command": "pnpm --prefix kinit-admin run dev",
"name": "Run BO",
"request": "launch",
"type": "node-terminal"
}
]
}
参考:
- 官网: https://gitee.com/ktianc/kinit
- FastAPI: Learn - FastAPI