Set http response Content-Type to "xml" in python

5.5k Views Asked by At

How do I display on an html page an xml?

how can I set in python text/html?

I'm writing in the html as:

response.out.write
1

There are 1 best solutions below

5
On BEST ANSWER

Assuming your using mod_python:

response.content_type = "text/xml"

Or:

response.content_type = "text/html"

http://www.modpython.org/live/current/doc-html/pyapi-mprequest-mem.html

content_type

String. The content type. Mod_python maintains an internal flag (req._content_type_set) to keep track of whether content_type was set manually from within Python. The publisher handler uses this flag in the following way: when content_type isn't explicitly set, it attempts to guess the content type by examining the first few bytes of the output.


If you just want to have pretty xml output in a text file, use BeautifulSoup prettify() on the xml.