olive wrote:
> Hello,
>
> I'm trying to send som UTF-8 data this way:
>
> json = serializers.serialize("json", myQuerySet, ensure_ascii=False)
> return HttpResponse(json, mimetype="text/javascript; charset=UTF-8")
>
> But the accented characters are not displayed properly in the browser.
>
>
> But if I put this on the first line of my views.py:
>
> # -*- coding: UTF-8 -*-
>
> and I try to send hard coded data this way:
>
> json = '[{"pk": "1", "model": "body.datacontent", "fields":
> {"content": "Heading à 1", "type": "hdg"}},{"pk": "2", "model":
> "body.datacontent", "fields": {"content": "Para 1", "type": "par"}}]'
>
> Then "Heading à 1" is properly displayed in the browser.
>
>
> Question: am I using serializers.serialize the right way or is it
> broken ?
i think you're using it the right way..
actually the problem lies somewhere in simplejson (the library that the
json-serializer uses).
example:
a = u'gábor'
b = a.encode('utf-8')
from django.utils.simplejson import dumps
In [37]: dumps(a,ensure_ascii=False)
Out[37]: u'"g\xe1bor"'
In [38]: dumps(a,ensure_ascii=True)
Out[38]: '"g\\u00e1bor"'
In [39]: dumps(b,ensure_ascii=False)
Out[39]: '"g?\xa1bor"'
In [40]: dumps(b,ensure_ascii=True)
Out[40]: '"g\\u00c3\\u00a1bor"'
so the unicode-string versions work fine, but with the
bytecode-versions, it just doesn't work.
gabor
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---