'ascii' codec can't encode character

13 views
Skip to first unread message

Thiago Luiz Parolin

unread,
Apr 28, 2022, 8:02:49 PM4/28/22
to django...@googlegroups.com
Hi,
i have a model with 2 charfields for givenname, surname:

   nome = models.CharField(
        max_length=150,
        verbose_name=_("Nome"),
        default=''
    )
    sobrenome = models.CharField(
        max_length=150,
        verbose_name=_("Sobrenome"),
        default=''
    )

My modelForm does nothing, just defines a model at Meta with all fields.
My CreateView is just defined with all default values, not overriding anything.
When submitting the form, the server returns 500 if 'nome' or 'sobrenome' fields have accent letters like Á, é, í, ç. etc.

The error:
'ascii' codec can't encode character '\xe9' in position 4: ordinal not in range(128)
with character depending on user input.

I am using sqlite for db and the pragma encoding returns utf8.

I don't know how to deal with it.
Any help would be appreciated.

Antonis Christofides

unread,
Apr 29, 2022, 5:55:46 AM4/29/22
to django...@googlegroups.com

Hi, could you post the full traceback? And if some part of this traceback refers to your code, it would be a good idea to also show us that part of your code.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CANbmKyvUWshdM3ENz9LjbG66rLkt4vruM6cC9M-%3DKmL7rcCR%2Bg%40mail.gmail.com.

David Crandell

unread,
Apr 29, 2022, 9:22:18 AM4/29/22
to Django users
You'd actually want to handle UNICODE strings, not ASCII.

Reply all
Reply to author
Forward
0 new messages