I have problems width encoding characters in (html) template. In my database there are results like :
- Čaša
- Šišanje
That words are in Croatian language. In my settings.py where LANGUAGE_CODE I have set : LANGUAGE_CODE = 'hr-HR' also tryd with LANGUAGE_CODE = 'hr'. The problem is 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 all record for that field must be render in HTML page, as selectpicker. When I try to load that page I get this 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 my models.py, the model is :
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 also 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 you know any easy way to solve this problem, I know python 3 have better utf encoding, but I wanna stay on 2.7.