Django 'ascii' codec can't encode character

心已入冬 提交于 2019-12-04 22:56:27

try to use unicode() to convert value (instead of str()):

data = unicode(value)
max4ever

If you're using django and python 2.7 this fixes it for me:

from django.utils.encoding import python_2_unicode_compatible

@python_2_unicode_compatible
class Utente(models.Model):

see https://docs.djangoproject.com/en/dev/ref/utils/#django.utils.encoding.python_2_unicode_compatible

@max4ever 's answer works for me. also sometimes you should put this line in the head of python files:

from __future__ import unicode_literals

it can be helpful when solving unicode encoding issues like this one.

in settings.py add this

import sys
reload(sys)
sys.setdefaultencoding('UTF8')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!