【发布时间】:2021-06-20 11:00:53
【问题描述】:
我有一个如下所示的 Flask 应用程序:
@app.route('/')
def index():
headline = render_template('headline.html', headline = 'xyz') #-> return <h1>xyz</h1>
return render_template('page.html', headline = headline) # insert headline html into a page
headline.html 是一个从宏文件 (macros.html) 中导入 jinja 宏的模板。宏生成标题。
headline.html:
{% import 'macros.html' as macros %}
{{ macros.get_headline(headline) }}
macros.html:
{% macro get_headline(headline) %}
<h1>{{ healine }}</h1>
{% endmacro %}
我的问题是——是否可以调用宏来获取headline无需调用模板headline.html?
理想情况下,我想看看
@app.route('/')
def index():
headline = # somehow call get_headline('xyz') from macros.html
return render_template('page.html', headline = headline) # insert headline html into a page
【问题讨论】: