使用render_template有条件地呈现HTML段 [英] Conditional rendering of HTML segment using render_template
本文介绍了使用render_template有条件地呈现HTML段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从几个不同的地方调用 render_template
,并且我想根据我从哪里调用来控制是否渲染某些HTML段.
I am calling render_template
from a couple of different places, and I'd like to control whether I render certain HTML segments, depending on where I'm calling from.
例如:
render_template('index.html', form=form, show_results=1)
我打算使用 show_results
bool标记是否应渲染可选片段.但是,我缺少了在HTML代码的可选定界部分中应具有的包装程序来控制是否应呈现该段.我该怎么做?
I intended to use the show_results
bool to flag whether the optional segment should be rendered or not. However, I'm missing what wrapper I should have in the optional delimited portion of the HTML code to control whether the segment should be rendered or not. How can I accomplish this?
推荐答案
使用 if阻止:
{% if show_results %}
show the results
{% endif %}
这篇关于使用render_template有条件地呈现HTML段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文