首页 > 解决方案 > Airfow 提供静态 html 目录

问题描述

我在以下位置使用 sphinx 构建了静态 html 文档:

$AIRFLOW_HOME/plugins/docs/

我想在 Airflow UI 中创建一个新的菜单链接“我的文档”,这样就可以了:

class DocsView(BaseView):
    @expose("/")
    def my_docs(self):
        return send_from_directory(os.path.abspath("plugins/docs/build/html"), 'index.html')

docs_view = DocsView(
    category="My Documentation",
    name="Plugins",
    endpoint="my_docs"
)

在我的自定义插件类中:

class MyPlugin(AirflowPlugin):
    admin_views = [docs_view]

该链接已成功显示在菜单栏中并且有效,但仅适用于 index.html。我不使用模板,只需要可以阅读所有自定义代码文档的部分。

标签: pythonflaskairflow

解决方案


我找到了解决方案。我必须在DocsView中添加静态 url 和文件夹路径,因为 sphinx 在build/html中创建了其他目录:

docs_view = DocsView(
    static_folder=os.path.abspath("plugins/docs/build/html"),
    static_url_path="/",
    category="My Documentation",
    name="Plugins",
    endpoint="my_docs"
)

推荐阅读