On 4/5/07, johnny <[EMAIL PROTECTED]> wrote:
> This is simple question.  When you send xml over http, do you just
> pass string varible containing the xml document, as a variable to the
> template?

For XML it's best not to use a template at all; while you may be used
to using the 'render_to_response' shortcut -- which requires a
template and a context dictionary -- keep in mind that it's just a
shortcut. What 'render_to_response' does is automate the common case
of loading a template, rendering it with a given context, and
returning an HttpResponse from that.

Because of the constraints of XML, a better method is to use a
dedicated XML-generation library to build up the XML document and then
serialize it to a string, at which point you can instantiate and
return an HttpResponse directly. The HttpResponse class constructor
takes two arguments:

1. A string to use as the content of the response. Normally this
string comes from the output of rendering a template, but in this case
it would be your serialized XML document.

2. An HTTP content-type to use, passed as the keyword argument 'mime_type'.

So in this case the best practice would be to build up your XML
document and serialize to a string, then do:

    return HttpResponse(the_xml_string, mime_type='application/xml')

Remember to import HttpResponse from the 'django.http' module before
using it in this fashion.

-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to