I’m using following model to store info about pages:
class Page(models.Model):
title = models.TextField(blank = False, null = False)
New data saves correctly, I’m saving Unicode data there (lots of non-ASCII titles).
But when I’m performing query:
page = Page.objects.filter(id = 1)
page.title looks odd:
u'\u042e\u0449\u0435\u043d\u043a\u043e'
What could I made wrong?
Thanks.
Update: Really, when I’m print page.title – it looks OK.
But I need to dump it to JSON, so after such code:
dumps({'title': page.title})
All looks bad.
Update 2: Thanks to everyone, pointed me that this behavoir is correct. But unicode-escaped strins are so long. Can I translate them to utf-8 somehow?
That’s correct behaviour:
dumpsencodes the json for you. It looks ugly now, but that’s just for transmission. To see your unicode string again have to decode it (usually on the other end):Generally you won’t need to decode it in python, it’ll get loaded as a unicode string in javascript.