Django/DRF/RBAC 权限与常用 AI 接口封装
Project description
django-base-ai
Django / DRF / RBAC 权限与常用基础能力封装,可作为业务项目的基础依赖包(如 DocsAI、Survey 等)复用。
- Python:3.9+
- 包名:
django-base-ai(导入名:django_base_ai)
功能概览
| 模块 | 说明 |
|---|---|
| RBAC | 用户、角色、部门、菜单、按钮权限、接口白名单、数据权限过滤 |
| 认证 | JWT(SimpleJWT)、单点登录、第三方登录、验证码 |
| 系统配置 | 字典、系统配置键值、调度与配置中心(dispatch) |
| 基础能力 | 文件上传/列表、导入导出(Excel)、操作日志、消息中心、WebSocket |
| 工具 | 统一 JSON 响应、分页、异常处理、权限校验(validation_api)、加解密、任务执行等 |
安装
# 克隆或进入项目目录
cd DjangoBaseAi
# 依赖安装
pip install -r requirements.txt
# 或可编辑安装(开发时推荐)
pip install -e ".[dev]"
[dev] 会安装 pytest、pytest-django、ruff。
在项目中使用
-
安装:将本仓库可编辑安装或打包后安装到目标 Django 项目环境。
-
配置:在目标项目的
settings.py中:- 将
django_base_ai加入INSTALLED_APPS - 按需配置数据库、缓存、JWT、CORS 等(可参考本仓库
DjangoBaseAi/settings.py或django_base_ai/settings.py) - 自定义异常处理:
EXCEPTION_HANDLER = "django_base_ai.utils.exception.custom_exception_handler"
- 将
-
路由:在目标项目
urls.py中挂载:from django_base_ai.system.urls import urlpatterns as system_urls urlpatterns = [..., path("api/", include(system_urls))]
-
初始化:执行迁移、并可通过
django_base_ai.dispatch及 system fixtures 初始化菜单、角色、字典等。
项目结构(简要)
DjangoBaseAi/
├── django_base_ai/ # 主包(供其他项目安装引用)
│ ├── dispatch.py # 配置/调度入口
│ ├── settings.py # 默认配置片段
│ ├── system/ # 系统模块:模型、视图、权限、fixtures、management 命令
│ ├── utils/ # 工具:认证、权限、响应、分页、导入导出、加解密等
│ ├── websocket/ # WebSocket 路由与配置
│ └── templates/
├── DjangoBaseAi/ # 本仓库作为“可运行项目”时的应用入口(settings、asgi、urls)
├── conf/ # 环境配置(env/test/pro)
├── tests/ # pytest 测试
├── pyproject.toml # 项目与 ruff/pytest 配置
├── requirements.txt
└── README.md
开发约定(与 Rules/python.mdc 一致)
- PEP 8:全包使用小写+下划线命名,
ruff format .与ruff check .通过后再提交。 - 类型与文档:新代码与核心模块使用类型注解与 docstring。
- 测试:使用 pytest,
DJANGO_SETTINGS_MODULE已写在pyproject.toml,在项目根执行pytest即可。
常用命令
# 代码格式与检查
ruff format .
ruff check . --fix
# 测试
pytest
pytest tests/ -v
# 打包
pip install build && python -m build
许可证
见仓库根目录 LICENSE。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_base_ai-0.0.2.tar.gz.
File metadata
- Download URL: django_base_ai-0.0.2.tar.gz
- Upload date:
- Size: 194.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42d72598547563fb50fb7435b62b3fac117c4e8152e354de8f939c33802dc02b
|
|
| MD5 |
56a054d1edebe186b693e09b066df021
|
|
| BLAKE2b-256 |
58263ad695e1f0a4c83ed5c885f82924b97db5f97fb71093fc9f3dabbefb0445
|
File details
Details for the file django_base_ai-0.0.2-py3-none-any.whl.
File metadata
- Download URL: django_base_ai-0.0.2-py3-none-any.whl
- Upload date:
- Size: 457.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ef1616aa0a582df530d049f53fc7585516902633ea5621a810c13f5017e3414
|
|
| MD5 |
eb028c71b689aadcac5467f0e1c9a3a4
|
|
| BLAKE2b-256 |
ca5d5a94393aa2bf5809285197903552910bf4ea3354f8b1b6814d9f3ccc0e46
|