python - Airflow 提供静态 html 目录

标签 python flask airflow

我有使用 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。我不使用模板,只需要可以读取所有自定义代码文档的部分。

最佳答案

我找到了解决方案。我必须在 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"
)

关于python - Airflow 提供静态 html 目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56461918/

相关文章:

python - 有没有办法让Jython py_compile不记录源文件的绝对路径?

python - 导入错误 : cannot import name 'url_encode' from 'werkzeug'

python - 验证 JSONLint 上的 AWS json 响应

python - 操作 Pandas 数据框

python - jinja2 静态文件 mime 类型总是文本/纯文本

python - apache 2 和 flask,reportlab registerFont "TTFError: Can' t 打开文件 ...“但在开发服务器上工作

python - 当我旋转 Airflow docker 然后再旋转它时,连接消失

python-3.x - 使用 Airflow _DataProcJob Hook 禁用数据处理中的附加作业

postgresql - 用于近实时 ETL 架构的正确工具

python - 将图像从 RGB 转换为 LUV 并返回会产生不同的图像