我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用django.utils.encoding.python_2_unicode_compatible()。
def to_str(self): """ Due to the way python_2_unicode_compatible works, this does not work: @python_2_unicode_compatible class GoogleAccount(ProviderAccount): def __str__(self): dflt = super(GoogleAccount, self).__str__() return self.account.extra_data.get('name', dflt) It will result in and infinite recursion loop. That's why we add a method `to_str` that can be overriden in a conventional fashion, without having to worry about @python_2_unicode_compatible """ return self.get_brand()['name']