Plotly-DashGo 开源项目使用教程
1. 项目介绍
Plotly-DashGo 是一个基于 Python 技术栈的开箱即用的全栈快速开发框架。它基于 Plotly Dash 框架和 Fac 开源组件库进行开发,允许开发者使用 Python 语言实现全栈的后台管理系统。Plotly-DashGo 拥有多页面管理、细粒度权限管理、自带用户和角色权限管理、国际化组件、密码和 OTP 登录、OAuth2 接口支持等特性,非常适合需要快速构建企业级后台管理系统的开发者。
2. 项目快速启动
环境准备
确保您的系统中已安装 Python。根据您的操作系统,选择相应的依赖文件进行安装:
- Windows 用户:运行
python -m pip install -r requirements_win.txt
- Linux 用户:运行
python -m pip install -r requirements_linux.txt
推荐使用虚拟环境进行开发,具体设置请参考虚拟环境设置教程。
初始化数据库和启动应用
切换到项目的 src
目录下:
- Windows:
cd /d e:\xxxx
- Linux:
cd /app/xxxx
初始化数据库表结构和 admin 管理员数据:
- 运行
python -c "from database.sql_db.conn import create_rds_table; create_rds_table()"
初始化表结构 - 运行
python -c "from database.sql_db.conn import init_rds_data; init_rds_data()"
初始化 admin 用户
启动应用:
- Windows: 运行
waitress-serve --host=0.0.0.0 --port=8090 --url-scheme=http --trusted-proxy=* --trusted-proxy-headers=x-forwarded-for --threads=8 app:server
- Linux: 运行
gunicorn --capture-output -w 4 -b 0.0.0.0:8090 app:server
默认账号为 admin
,密码为 admin123
。启动后,根据日志提示中的 URL 进行访问。
如果需要使用任务中心模块,运行 python app_apscheduler.py
启动任务进程。
请注意,默认启动使用的是 sqlite 数据库。如需用于生产环境,请根据 config/dashgo.ini
调整相关 MySQL 数据库配置。
3. 应用案例和最佳实践
以下是一个简单的应用案例,展示如何在 Plotly-DashGo 中添加新应用:
# 导入所需的模块
from common.utilities.util_menu_access import MenuAccess
import feffery_antd_components as fac
import feffery_utils_components as fuc
from common.utilities.util_logger import Log
from dash_components import Card
# 设置应用的标题、图标和显示顺序
title = '应用1'
icon = None
order = 2
logger = Log.get_logger(__name__)
# 注册权限
access_metas = (
'应用1-基础权限',
'应用1-权限1',
'应用1-权限2',
)
# 定义视图页面的渲染方法
def render_content(menu_access: MenuAccess, **kwargs):
return fac.AntdFlex([
[
Card(
fac.AntdStatistic(
title='展示',
value=fuc.FefferyCountUp(end=100, duration=3),
),
title='应用1-权限1',
)
] if menu_access.has_access('应用1-权限1') else [],
[
Card(
fac.AntdStatistic(
title='展示',
value=fuc.FefferyCountUp(end=200, duration=3),
),
title='应用1-权限2',
)
] if menu_access.has_access('应用1-权限2') else [],
], wrap='wrap')
在 Plotly-DashGo 中,最佳实践是按照项目的结构组织代码,确保代码的模块化和可维护性。
4. 典型生态项目
目前,Plotly-DashGo 的生态项目包括但不限于:
- dashgo-knowledge:一个自主开发的子系统,通过 OAuth2 接口和 Iframe 实现接入。
开发者可以根据自己的需求,创建和集成更多生态项目,以丰富 Plotly-DashGo 的功能和应用场景。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考