Python 我不知道';我不理解Jinja2呼叫模块

Python 我不知道';我不理解Jinja2呼叫模块,python,jinja2,Python,Jinja2,我理解这个概念,但不理解语法 我将使用他们网站上使用的 {% macro render_dialog(title, class='dialog') -%} <div class="{{ class }}"> <h2>{{ title }}</h2> <div class="contents"> {{ caller() }} </div> </div> {%- endmacro %}

我理解这个概念,但不理解语法

我将使用他们网站上使用的

{% macro render_dialog(title, class='dialog') -%}
<div class="{{ class }}">
    <h2>{{ title }}</h2>
    <div class="contents">
        {{ caller() }}
    </div>
</div>
{%- endmacro %}

{% call render_dialog('Hello World') %}
   This is a simple dialog rendered by using a macro and
    a call block.
{% endcall %}
{%macro render_对话框(title,class='dialog')-%}
{{title}}
{{caller()}}
{%-endmacro%}
{%call render_dialog('Hello World')%}
这是一个使用宏和
呼叫区。
{%endcall%}
输出是什么

子问题(因为我对它的工作原理感到困惑):每个宏是否只允许有一个调用者

这是输出:

<div class="dialog">
    <h2>Hello World</h2>
    <div class="contents">

   This is a simple dialog rendered by using a macro and
    a call block.

    </div>
</div>

你好,世界
这是一个使用宏和
呼叫区。

因此,当我们调用render_对话框时,我们将“Hello World”作为标题传递,当它到达
caller()
时,它将传递
call
块的内容。

Cool。那么,这与在另一个宏中调用宏有什么不同呢?您可以将宏视为传统语言中的函数。调用块只是对该函数的调用。我发现在嵌套宏中运行
caller()
的嵌套宏出现错误,因为没有调用方数据传递给它。我真正想要的是传递给父宏的数据。我可以通过在外部宏中执行
{%set content=caller()%}
然后在内部宏中使用
{{content}
来实现这一点。