diff --git a/README.md b/README.md index 79e85b7..4edbbe0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@

- Pear Admin Layui Version + Pear Admin Layui Version Python Version diff --git a/applications/extensions/__init__.py b/applications/extensions/__init__.py index b1f9913..8849131 100644 --- a/applications/extensions/__init__.py +++ b/applications/extensions/__init__.py @@ -18,9 +18,11 @@ def init_plugs(app: Flask) -> None: # 注册 Flask 功能 init_login_manager(app) init_databases(app) - init_template_directives(app) - init_error_views(app) init_mail(app) init_upload(app) init_migrate(app) init_session(app) + + # 系统蓝图相关 + init_template_directives(app) + init_error_views(app) diff --git a/docs/source/_static/Pear Admin Flask 启动流程图.drawio b/docs/source/_static/Pear Admin Flask 启动流程图.drawio new file mode 100644 index 0000000..ffb2f75 --- /dev/null +++ b/docs/source/_static/Pear Admin Flask 启动流程图.drawio @@ -0,0 +1,247 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/source/_static/Pear Admin Flask 启动流程图.png b/docs/source/_static/Pear Admin Flask 启动流程图.png new file mode 100644 index 0000000..2d7a71e Binary files /dev/null and b/docs/source/_static/Pear Admin Flask 启动流程图.png differ diff --git a/docs/source/practices/backend.rst b/docs/source/practices/backend.rst new file mode 100644 index 0000000..2e4b95a --- /dev/null +++ b/docs/source/practices/backend.rst @@ -0,0 +1,27 @@ +后端页面编写 +====================== + +该章节将介绍如何在 Pear Admin Flask 中编写一个新后端页面,此章节将会以编写积分兑奖系统为例,编写一个兑换码管理的后台页面。 + +.. _项目初始化逻辑: + +项目初始化逻辑 +----------------------- + +我们知道,一个简单的 Flask 项目是从 `app = Flask(__name__)` 开始的,而 Pear Admin Flask 的初始化的逻辑同理也是在此基础上,不过稍加复杂了一点。 +下面这张图片将会揭示项目初始化的逻辑。(点击可查看大图) + +| + +.. image:: ../_static/Pear\ Admin\ Flask\ 启动流程图.png + :target: ../_static/Pear\ Admin\ Flask\ 启动流程图.png + :align: center + +| + +由此可以看出,我们想要添加自己的后端页面,可以在 “注册项目的视图函数”(蓝框) 的地方添加,当然,同样页面可以作为插件的方式接入以提高项目的拓展性。 +下面将介绍如何在这两种方式下添加自己的后台页面。 + + + + diff --git a/docs/source/practices/index.rst b/docs/source/practices/index.rst index 94e78c2..7df4d33 100644 --- a/docs/source/practices/index.rst +++ b/docs/source/practices/index.rst @@ -7,4 +7,5 @@ plugin trick - frontend \ No newline at end of file + frontend + backend \ No newline at end of file diff --git a/docs/source/practices/plugin.rst b/docs/source/practices/plugin.rst index 321bfb8..56874fc 100644 --- a/docs/source/practices/plugin.rst +++ b/docs/source/practices/plugin.rst @@ -133,8 +133,13 @@ pass def event_context(app: Flask): # Flask 初始化完成,等待第一个请求之前,等同于 with app.app_context(): + # 此时数据库已经初始化完成,尝试读取 pass +.. note:: + + 事件的时机调用可以参考 :ref:`项目初始化逻辑` 章节。 + .. important:: 注意不要直接在 `__init__.py` 的函数外直接写存在阻塞的代码,不然项目 Flask 将不能初始化完成。 diff --git a/docs/source/practices/trick.rst b/docs/source/practices/trick.rst index f3a9510..f823a0f 100644 --- a/docs/source/practices/trick.rst +++ b/docs/source/practices/trick.rst @@ -35,6 +35,11 @@ 使用不同的数据库需要安装另外的库,比如 mysql 要安装 pymysql 库(不同平台可能名称不一样),请自行查询资料而后进行配置。 +添加后台菜单 +------------ + +在 Pear Admin Flask 中,菜单的管理归属于 “权限管理” ,这样做的原因是为了使不同用户可以使用不同的访问控制。所以需要修改菜单,需要在 “权限管理” 页面编辑即可。 + 权限效验 ------------ @@ -186,7 +191,7 @@ Schema 序列化 详情查看 :ref:`JSON 响应正文生成模块` 章节。 -发送硬件 +发送邮件 ----------------------- 程序提供了发送邮件的模块,前提是需要正确在 `applications/config.py` 中配置 SMTP 服务器。详情查看 ref:`邮件模块` 章节。 diff --git a/docs/source/welcome/instruction.rst b/docs/source/welcome/instruction.rst index e7d307a..fb64bbf 100644 --- a/docs/source/welcome/instruction.rst +++ b/docs/source/welcome/instruction.rst @@ -27,7 +27,7 @@

- Pear Admin Layui Version + Pear Admin Layui Version Python Version diff --git a/docs/source/welcome/migration.rst b/docs/source/welcome/migration.rst index 2481b9d..6e16ba8 100644 --- a/docs/source/welcome/migration.rst +++ b/docs/source/welcome/migration.rst @@ -110,4 +110,21 @@ .. code-block:: python - from applications.common.admin import admin_log \ No newline at end of file + from applications.common.admin import admin_log + +验证码生成路由修改 +~~~~~~~~~~~~~~~~~~~~~~~~ + +为了优化代码,将验证码生成路由改为了 system.passport.captcha 。这主要会影响前端模板渲染。 + +例如: + +.. code-block:: html + + url_for('system.passport.get_captcha') + +改为: + +.. code-block:: python + + url_for('system.passport.captcha') diff --git a/docs/source/welcome/update.rst b/docs/source/welcome/update.rst index 039c1ee..84b5cbb 100644 --- a/docs/source/welcome/update.rst +++ b/docs/source/welcome/update.rst @@ -40,6 +40,8 @@ * 更正登录之后重定向由于路由更改从而设置错误的问题 * 将 applications/common/admin_log.py 与 applications/common/admin.py 合并,仅留下 applications/common/admin.py * 优化代码结构,新增函数 `normal_log` 减少代码复用 +* 添加了新插件的事件 +* 修改了验证码生成路由 已知问题以及解决方式 ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/plugins/helloworld/__init__.py b/plugins/helloworld/__init__.py index c6c6fc1..1e560e3 100644 --- a/plugins/helloworld/__init__.py +++ b/plugins/helloworld/__init__.py @@ -32,7 +32,8 @@ def event_finish(app: Flask): # 在项目所有功能注册之后调用(插 def event_context(app: Flask): # Flask 初始化完成,等待第一个请求之前,等同于 with app.app_context(): print("第一个请求来之前加载") + # 数据库已经初始化完成,尝试读取 dept = Dept.query.order_by(Dept.sort).all() power_data = curd.model_to_dicts(schema=DeptSchema, data=dept) - print(power_data) + # print(power_data) diff --git a/templates/system/login.html b/templates/system/login.html index 19d9d45..4018f11 100644 --- a/templates/system/login.html +++ b/templates/system/login.html @@ -96,7 +96,7 @@ var popup = layui.popup; let layer = layui.layer; let $ = layui.jquery; - let captchaPath = "{{ url_for('system.passport.get_captcha') }}"; + let captchaPath = "{{ url_for('system.passport.captcha') }}"; /**