sandeep
sandeep

Reputation: 3345

Escaping Particular Special Characters

I have a string like: 'SEBASTIÁN', and when I save this in the db, it saves as encoded. While trying to show it in frontend through python code it's throwing an error.

In [1]: p = "SEBASTIÁN"

In [2]: p
Out[2]: 'SEBASTI\xc3\x81N'

How can I fix this?

Upvotes: 0

Views: 100

Answers (3)

dusual
dusual

Reputation: 2207

You should be saving this as a unicode string

>>>p = u"SEBASTIÁN"
>>> print p
SEBASTIÁN

Upvotes: 0

Emilio M Bumachar
Emilio M Bumachar

Reputation: 2613

I don't know django, but this works in python 3:

>>> b'SEBASTI\xc3\x81N'.decode("utf-8", "strict")
'SEBASTIÁN'

Upvotes: 0

Pavel Anossov
Pavel Anossov

Reputation: 62868

Use unicode strings with django.

u"SEBASTIÁN"
↑

Please read this: https://docs.djangoproject.com/en/dev/ref/unicode/

Upvotes: 5

Related Questions