如何更改布尔值在django模板中打印的方式? [英] How can I change the way a boolean prints in a django template?
本文介绍了如何更改布尔值在django模板中打印的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它呈现为True或False,我可以将标签更改为同意/不同意,还是需要在模板中写入逻辑?
解决方案
{{bool_var | yesno:同意,不同意}}
您还可以为无案例提供一个额外的字符串。有关详细信息,请参阅 yesno 的文档。
I have some django code that prints a BooleanField
it is rendered as True or False, can I change the label to be Agree/Disagree or do I need to write logic for that in the template?
解决方案
{{ bool_var|yesno:"Agree,Disagree" }}
You can also provide an additional string for the None case. See the docs for yesno for details.
这篇关于如何更改布尔值在django模板中打印的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文