Python / Django - 如果模板中的if语句扩展 [英] Python / Django - If statement in template around extends
本文介绍了Python / Django - 如果模板中的if语句扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想有一个有条件地扩展的模板。基本上,当一个名为ajax的变量是真的,我不想让模板扩展另一个。
I would like to have a template that extends another conditionally. Basically, when a variable called "ajax" is true I DO NOT want to have the template extend another.
{% if not ajax %}
{% extends "/base.html" %}
{% endif %}
任何线索?
推荐答案
你不能这样做。然而,您可以设置一个变量并使用它来选择扩展的模板:
You cannot do it like that. You can however set a variable and use that to choose the template to extend:
{% extends my_template %}
然后在python代码中,你写的东西如下:
Then in python code you write something like:
if ajax:
template_values['my_template'] = 'base_ajax.html'
else:
template_values['my_template'] = 'base.html'
您可能希望请参阅文档获取更多信息。
You may wish to refer to the documentation for more information.
这篇关于Python / Django - 如果模板中的if语句扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文