Tho*_*mel 6 django-templates django-models
我在Contact模型中定义了一个unicode()方法.
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
Run Code Online (Sandbox Code Playgroud)
现在我想在模板中显示unicode()方法的返回值.
但我尝试的一切都失败了.
{{ object.unicode }}
Run Code Online (Sandbox Code Playgroud)
要么
{{ object.unicode() }}
Run Code Online (Sandbox Code Playgroud)
要么
{{ object.__unicode__ }}
Run Code Online (Sandbox Code Playgroud)
要么
{{ object.str }}
Run Code Online (Sandbox Code Playgroud)
这让我很困惑,因为我有另一个模型级函数,可以从模板中引用而没有问题.
这很好用:
def get_id(self):
return "%i" % self.id
{{ object.get_id|escape }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4936 次 |
| 最近记录: |