我已经能够使用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渲染模板
发布评论