Django: Non-ASCII character

后端 未结 7 1781
清歌不尽
清歌不尽 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条回答
  •  孤独总比滥情好
    2020-12-23 15:24

    You need the coding comment Gabi mentioned and also use the unicode "u" sign before your string :

    return HttpResponse(u'español')
    

    The best page I found on the web explaining all the ASCII/Unicode mess is this one : http://www.stereoplex.com/blog/python-unicode-and-unicodedecodeerror

    Enjoy!

提交回复
热议问题