Why is the Django admin trying to encode strings in ASCII and not in Unicode? Or is this mistake different from her?

I have the following error:

TemplateSyntaxError at / Admin / results_cop / copsegmentresult /

Rendering exception showing: ('ascii', 'ISU Figure Skating in Europe Championship 2009: Senior Ladies Ladies: short program - 2. Suzanne P \ xc3 \ x96YKI \ xc3 \ x96', 98, 99, 'ordinal not in range ( 128) ')

Fragment of a line that will not be displayed: PÖYKIÖ

I don’t understand why Django is trying to display the string as ASCII, why not UTF-8?

EDIT 1:

I forgot to ask - I would also really like to know how to get rid of the error;)

EDIT 2:

Bobin answered correctly :) I had something like:

def __unicode__(self):
    return "%s %s" (self.foo, self.bar)
+3
2

, Django . u :

'ISU European Figure Skating Championships 2009: Senior Ladies Ladies: Short Program - 2. Susanna P\xc3\x96YKI\xc3\x96'

, Django, , , UTF-8. ; Unicode. Python , , ascii.

>>> 'P\xc3\x96YKI\xc3\x96'.encode('utf-8')
UnicodeDecodeError

, Unicode UTF-8-, ​​ . ? Unicode.

+7

- bobince, :

Unicode.

, :

def __unicode__(self):
  return "{0}".format(self.field_one)

ASCII ( , field_one ASCII), field_one ASCII, , .

:

def __unicode__(self):
      return self.field_one

, unicode , .

unicode, , u, unicode

def __unicode__(self):
      return u"{0}".format(self.field_one)
+3

Source: https://habr.com/ru/post/1727288/


All Articles