I got views.py:
# -*- coding: UTF-8 -*-
def myview(request):
object = MyObject.objects.get(id = 1)
testvar = u"test %s" % object.myfield
And I got error:
UnicodeDecodeError at /myurl
'ascii' codec can't decode byte 0xc4 in position 1: ordinal not in range(128)
Unicode error hint
The string that could not be encoded/decoded was: J������
J������ - myfield value In database this field is utf8_bin. In model this field is CharField
sys.getfilesystemencoding() #- UTF-8
sys.getdefaultencoding() #- ascii
sys.getdefaultencoding() #- ascii
locale.getdefaultlocale() #- ('en_US', 'UTF-8')
locale.getlocale() #- (None, None)
Python 2.7.6 Django 1.5.8
I tried also:
object.myfield.decode("utf8")
And got error:
UnicodeEncodeError at /myurl
'ascii' codec can't encode characters in position 6-10: ordinal not in range(128)
I have administration side of this object - and everything works perfect, even with utf-8 symbols.
And if I print out type of object.myfield, then i get:
<type 'str'>
myfielda foreign key? If it is, can you post __str__() and __unicode__() of related model?