On Aug 20, 11:27 pm, David Korz <[email protected]> wrote:
> Their
> solution is to require aBOMat the beginning of the document which I
> can't figure out how to do from Django.
>
> I tried putting aBOMin the template file and well as using a
> variable set to u"\xef\xbb\xef" but it either gets ignored (not in the
> rendered content) or gets mangled after returning (probably in the
> UTF-8 encoding the the fcgi/wsgi handler.
Putting the BOM in the template file worked for me, except that
Emacs's character code conversion (or something else below xml-mode)
ate it. After asking for help at Stack Overflow [1], I ended up
redefining render_to_response:
def render_to_response(*args, **kwargs):
bom = kwargs.pop('bom', False)
httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
s = django.template.loader.render_to_string(*args, **kwargs)
if bom:
s = '\xef\xbb\xbf' + s.encode("utf-8")
return HttpResponse(s, **httpresponse_kwargs)
I can now do render_to_response("foo.xml", mimetype="text/xml",
bom=True) in order to prepend the BOM to a particular response.
Vebjorn
[1]
http://stackoverflow.com/questions/1423916/prepend-bom-to-xml-response-from-django
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---