R
R
Rustem Vorozheikin2015-05-02 12:15:37
Django
Rustem Vorozheikin, 2015-05-02 12:15:37

Problem with Python(Django) encoding?

Good afternoon guys.
There was an encoding problem in Django.
Here's the thing, the input function receives data from the mongodb database and should return this string, which will be displayed on the site page.
String in mongodb: "Stretch fabric piqué polo"
String returned by the function: "Stretch fabric piqu\xe9 polo"
Here's how to make the function return the first option, and not the second?
My failed attempts:

1. return u'%s' % str(value)
2. from django.utils.safestring import SafeUnicode
  return SafeUnicode(str(value))

Python: 2.7, django: 1.7, mongodb 2.6 Any help
would be greatly appreciated =)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
un1t, 2015-05-02
@un1t

u'%s' % str(value)
this is generally a strange expression, what do you want to do - unicode(value)?

>>> s = u'Stretch fabric piqué polo'
>>> s
u'Stretch fabric piqu\xe9 polo'
>>> print s
Stretch fabric piqué polo
>>>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question