气流Jinja渲染模板

编程入门 行业动态 更新时间:2024-10-18 08:29:13
本文介绍了气流Jinja渲染模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经能够使用BaseOperator中的功能 render_template 成功渲染Jinja模板。

我的问题是,是否有人知道在 Rendered 或 Rendered Template 标签下将呈现的字符串输入UI的要求? / p>

在用户界面中引用此标签:

在此提供任何帮助或指导。

解决方案

如果在Operator中使用模板字段,则将在模板字段中显示创建的字符串。例如。使用BashOperator:

example_task = BashOperator( task_id ='task_example_task', bash_command ='mycommand --date {{task_instance.execution_date}}', dag = dag,)

然后bash命令将通过模板引擎进行解析(因为其中包括Jinja字段),稍后您可以在Web UI中看到您提到的解析结果。

不过,必须对字段进行模板化。可以在 templated_fields 字段的代码中看到。对于BashOperator(请参见此处的代码 github /apache/incubator-airflow/blob/master/airflow/operators/bash_operator.py )这是:

template_fields =('bash_command','env')

BashOperator中的其他字段不会被解析。

您可以使用宏命令(请参见 airflow.apache/code.html#macros )或来自xcom的信息(请参见 airflow.apache/concepts.html?highlight=xcom#xcoms )在模板字段中。

I've been able to successfully render Jinja Templates using the function within the BaseOperator, render_template.

My question is does anyone know the requirements to get rendered strings into the UI under the Rendered or Rendered Template tab?

Referring to this tab in the UI:

Any help or guidance here would be appreciated.

解决方案

If you are using templated fields in an Operator, the created strings out of the templated fields will be shown there. E.g. with a BashOperator:

example_task = BashOperator( task_id='task_example_task', bash_command='mycommand --date {{ task_instance.execution_date }}', dag=dag, )

then the bash command would get parsed through the template engine (since a Jinja field is included) and later on you could see the result of this parsing in the web UI as you mentioned.

The fields must be templated, though. This can be seen in the code in the field templated_fields. For BashOperator (see code here github/apache/incubator-airflow/blob/master/airflow/operators/bash_operator.py) this is:

template_fields = ('bash_command', 'env')

Other fields in the BashOperator will not be parsed.

You can use macro commands (see here airflow.apache/code.html#macros) or information from xcom (see here airflow.apache/concepts.html?highlight=xcom#xcoms) in templated fields.

更多推荐

气流Jinja渲染模板

本文发布于:2023-11-24 02:10:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623582.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:气流   模板   Jinja

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!