How can I change the way a boolean prints in a django template?

吃可爱长大的小学妹 提交于 2019-12-03 14:37:32

问题


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?


回答1:


{{ bool_var|yesno:"Agree,Disagree" }}

You can also provide an additional string for the None case. See the docs for yesno for details.



来源:https://stackoverflow.com/questions/845901/how-can-i-change-the-way-a-boolean-prints-in-a-django-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!