我们有基于此链接的Airflow 自定义 UI ,它在 Airflow 1.9.0 上运行良好。在此之后,我们升级到 1.10.1 并启用了 RBAC。在此之后,我们的自定义 UI 不再出现。
我们遵循了note-on-role-based-views 的说明,并尝试在 appbuilder_views 中使用我们的旧 UI 模板。在使用来自 /tests/plugins/test_plugin.py 的 TestAppBuilderBaseView 时,
class TestAppBuilderBaseView(AppBuilderBaseView):
@expose("/")
def test(self):
return self.render("test_plugin/test.html", content="Hello galaxy!")
Run Code Online (Sandbox Code Playgroud)
我们得到菜单和链接,但点击时我们得到错误
对象没有属性“渲染”
在将其更改为
return self.render_template("test_plugin/test.html",content="Hello galaxy!")
Run Code Online (Sandbox Code Playgroud)
我们得到错误
jinja2.exceptions.TemplateNotFound: test_plugin/test.html
我已经尝试了所有可能的组合来放置模板文件夹和 html 文件,但仍然是同样的错误。
我确实发现一些论坛告诉在蓝图上启用调试。但我不知道如何使用 Airflow 做到这一点
请问有这方面的指导吗?
提前
致谢
小智 7
发布时的 1.10.0 版本有一个错误,即未在新 UI 中正确安装插件。这在 1.10.1 版本中已修复,但 Airflow 文档中插件的代码示例已损坏。
我写了一个示例项目来使集成工作,您可以在这里查看:https : //github.com/felipegasparini/airflow_plugin_rbac_test
但简而言之,您需要:
使用以下命令从 appbuilder 正确导入 BaseView:
从 flask_appbuilder 导入 BaseView 作为 AppBuilderBaseView
将方法“test”的名称更改为“list”
将 template_folder 属性设置为指向您的模板所在的位置。
像这样的东西:
from airflow.plugins_manager import AirflowPlugin
from flask_appbuilder import BaseView as AppBuilderBaseView
class TestAppBuilderBaseView(AppBuilderBaseView):
template_folder = '/root/airflow/plugins/test_plugin/templates'
@expose("/")
def list(self):
return self.render_template("test.html", content="Hello galaxy!")
v_appbuilder_view = TestAppBuilderBaseView()
v_appbuilder_package = {"name": "Test View",
"category": "Test Plugin",
"view": v_appbuilder_view}
# Defining the plugin class
class AirflowTestPlugin(AirflowPlugin):
name = "test_plugin"
# operators = [PluginOperator]
# sensors = [PluginSensorOperator]
# hooks = [PluginHook]
# executors = [PluginExecutor]
# macros = [plugin_macro]
# admin_views = [v]
# flask_blueprints = [bp]
# menu_links = [ml]
appbuilder_views = [v_appbuilder_package]
# appbuilder_menu_items = [appbuilder_mitem]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1649 次 |
| 最近记录: |