[Fixed]-Django 'ascii' codec can't encode character

12👍

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

data = unicode(value)

29👍

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

6👍

@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.

👤realhu

4👍

in settings.py add this

import sys
reload(sys)
sys.setdefaultencoding('UTF8')

Leave a comment