Django with python 2.7 utf-8 problems -
i have problems width encoding characters in (html) template. in database there results :
- Čaša
- Šišanje
that words in croatian language. in settings.py language_code have set : language_code = 'hr-hr' tryd language_code = 'hr'. problem when database returns record in forms:
category = forms.modelchoicefield(queryset=category.objects.all().filter(type_id="2"), widget=forms.select(attrs={'class': 'selectpicker'}), label=('kategorija'), initial='1', )
and record field must render in html page, selectpicker. when try load page error:
- exception type: unicodeencodeerror
- exception value: 'ascii' codec can't encode character u'\u0107' in position ordinal not in range(128)
python version : 2.7.9
django version : 1.7.7
in models.py, model :
class category(models.model): id = models.autofield(primary_key=true) type_id = models.foreignkey('categorytype') name = models.charfield(max_length=255) def __str__(self): return str(self.name)
i have try with:
class category(models.model): id = models.autofield(primary_key=true) type_id = models.foreignkey('categorytype') name = models.charfield(max_length=255) def __str__(self): return self.name
do know easy way solve problem, know python 3 have better utf encoding, wanna stay on 2.7.
import sys reload(sys) sys.setdefaultencoding('utf-8')
have tried this?
Comments
Post a Comment