Django countries cannot get country name

Based on the django-countriesdocumentation,

>>> person.country
Country(code='NZ')
>>> person.country.name
u'New Zealand'

There must be a way to get unicode for the country name. However, when I try, I get

>>> obj.country
Country(code='AX')
>>> obj.country.name
<django.utils.functional.__proxy__ object at 0x91b81ac>

I exit countries.py and see that the choice is as follows:

('AX', ugettext_lazy('\xc5land Islands'))

Even when used, it print object.country.nameprints the same object. Why doesn't it work?

edit: Sorry, I just put the name object as an example: p

+5
source share
1 answer

Calling unicode () on it

https://docs.djangoproject.com/en/1.3/ref/unicode/#translated-strings

from django.utils.translation import ugettext_lazy

u = ugettext_lazy('hello')
print u
# out: <django.utils.functional.__proxy__ object at 0x158edd0>

print unicode(u)
# out: u'hello'

This is usually not a problem when rendering in a template.

+7
source

All Articles