当前位置: 代码迷 >> 综合 >> Django UnicodeEncodeError
  详细解决方案

Django UnicodeEncodeError

热度:13   发布时间:2024-01-20 19:58:51.0

1. event

Add Event item in Django admin. When I add a name which contain Chinese characters. It thrown a exception.

2. Error desc

‘ascii’ codec can’t encode characters in position 0-1: ordinal not in range(128)

3. solution

  • Add coding: utf-8 at head in manage.py script file, but it’s none work
  • I was referencing a blog topic, then get the work solution:
    add blow code in manage.py
reload(sys) sys.setdefaultencoding('utf-8')

It’s work!