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