On 21 jan, 12:55, Anders <[email protected]> wrote: > My django site uses iso-8859-1 as default output of all the web pages > (due to ssi intergration with other iso-8859-1 pages). > > So I have set: > DEFAULT_CHARSET = 'iso-8859-1' > FILE_CHARSET = 'iso-8859-1' > > and this works fine for alle the pages I serve. > > But now I have to serve an xml output for use with actionscript in a > Flash. This xml should be UTF-8 encoded. > > Is there som way I can convert the queryset to utf-8
<mode="pedantic"> I assume you mean "the queryset's contents that happens to be textual content" ?-) </mode> For the record, did you check how your queryset's textaul content was actually presented (I mean, in your view's python code) ? I think that reading http://docs.djangoproject.com/en/dev/ref/unicode/ might be a good starting point, paying special attention to http://docs.djangoproject.com/en/dev/ref/unicode/#models Now the bad news is that, still according to this same page: """ The DEFAULT_CHARSET setting controls the encoding of rendered templates """ http://docs.djangoproject.com/en/dev/ref/unicode/#templates > so that this will > work? Or can I convert each string as I output it in the template Why not just convert the rendered template ?-) > (yeah, I use the template to create xml - not good, I know). Well, this may not be the most efficient solution and that you don't have any validation, but I wouldn't label it as "not good". Django's templating system is here for generating templated text outputs, and whether what it generates is XML or XHTML or HTML or whatever is irrelevant. > In addition the render_to_response uses the default charset, is is > possible to override this default and use UTF-8? render_to_response() is just a (convenient) shortcut. In you case, the simplest solution IMHO would be to (in your view function): - explicitely load the template - render it and store the result - convert this result to utf-8 - pass this converted result to an HttpResponse object, specifying the appropriate content-type Content-Encoding. All this (except the encoding conversion, cf below) is documented in the FineManual(tm) - but feel free to ask here for more precision if necessary. NB : how to convert a bytestring from one encoding to another (assuming the string is effectively encoded as 'original-encoding' of course): result = thestring.decode('original-encoding').encode('another- encoding') HTH --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

