在模板中调用django模型函数

时间:2013-03-25 17:58:39

标签: django

我在模型中有以下功能:

@property
def exclusive_price(self):
    if(self.discount_price > 0):
        return self.list_price - self.discount_price
    else:
        return self.list_price

我尝试在模板中调用它,但没有输出任何内容。我该怎么办?

{{obj.exlusive_price}}

2 个答案:

答案 0 :(得分:15)

它无效,因为您调用的是exlusive_price而不是exclusive_price。 c缺失了。

答案 1 :(得分:1)

假设这不是剪切和粘贴错误,您的方法称为exclusive_price,但是您在没有exlusive_price的情况下调用c