Django: Non-ASCII character

后端 未结 7 1770
清歌不尽
清歌不尽 2020-12-23 15:12

My Django View/Template is not able to handle special characters. The simple view below fails because of the ñ. I get below error:

Non-ASCII character

7条回答
  •  萌比男神i
    2020-12-23 15:31

    I was struggling with the same issue as @dkgirl, yet despite making all of the changes suggested here I still could not get constant strings that I'd defined in settings.py that contain ñ to show up in pages rendered from my templates.

    Instead I replaced every instance of "utf-8" in my python code from the above solutions to "ISO-8859-1" (Latin-1). It works fine now.

    Odd since everything seems to indicate that ñ is supported by utf-8 (and in fact I'm still using utf-8 in my templates). Perhaps this is an issue only on older Django versions? I'm running 1.2 beta 1.

    Any other ideas what may have caused the problem? Here's my old traceback:
    Traceback (most recent call last):
    File "manage.py", line 4, in
    import settings # Assumed to be in the same directory.
    File "C:\dev\xxxxx\settings.py", line 53
    ('es', ugettext(u'Espa±ol') ),
    SyntaxError: (unicode error) 'utf8' codec can't decode byte 0xf1 in position 0: unexpected end of data

提交回复
热议问题