gpt4 book ai didi

python django 或条件

转载 作者:太空宇宙 更新时间:2023-11-04 07:29:21 24 4
gpt4 key购买 nike

我有这个代码:

{{ object.subtotal }}

如果 object.subtotal 为空或 false,我想打印 0:

我试过这样的:

{{ object.subtotal or 0 }}

但是我有一个服务器错误 500

最佳答案

您可以使用 default过滤器:

{{ object.subtotal|default:0 }}

关于python django 或条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51078402/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com