Mav*_*ick 14 python django python-unicode django-countries
我在django_countries
国家列表中使用模块,问题是有几个国家有特殊字符'Åland Islands'
和'Saint Barthélemy'
.
我正在调用此方法来获取国家/地区名称:
country_label = fields.Country(form.cleaned_data.get('country')[0:2]).name
Run Code Online (Sandbox Code Playgroud)
我知道country_label是django utils的懒惰翻译代理对象,但它没有给出正确的名称,而是给出了它'Ã…land Islands'
.对此有何建议?
尝试:
from __future__ import unicode_literals #Place as first import.
Run Code Online (Sandbox Code Playgroud)
和/或
country_label = fields.Country(form.cleaned_data.get('country')[0:2]).name.encode('latin1').decode('utf8')
Run Code Online (Sandbox Code Playgroud)