标签:
字段,属性,方法,列表
方法不被调用
>>> class Test(object):
def delete(self):
return ‘echo from delete...‘
delete.alters_data=True
>>> t.render(Context({‘t‘:Test()}))
u‘‘
在方法查找过程中,如果某方法抛出一个异常,除非该异常有一个 silent_variable_failure 属性并且值为 False ,否则的话它将被传播。设置为True,异常不被传播,模板里的指定变量会被 置为空字符串,比如:
>>> t = Template("My name is {{ person.first_name }}.")
>>> class PersonClass3:
... def first_name(self):
... raise AssertionError, "foo"
>>> p = PersonClass3()
>>> t.render(Context({"person": p}))
Traceback (most recent call last):
...
AssertionError: foo
>>> class SilentAssertionError(AssertionError):
... silent_variable_failure = True
>>> class PersonClass4:
... def first_name(self):
... raise SilentAssertionError
>>> p = PersonClass4()
>>> t.render(Context({"person": p}))
u‘My name is .‘
标签:
原文地址:http://www.cnblogs.com/Citizen/p/4351132.html