1

I wrote a simple requestHandler for my GAE application that should create an xml text and let the user download it.

class ExportHandler(webapp.RequestHandler):
    def get(self):
        r = "<someTag>tagText<someTag>" # sample xml
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write(r)

But it shows me an xml file contents on browser. Should I assign headers['Content-Type'] to something else? Or is there any better way to implement that? Thanks in advance.

AzaFromKaza
  • 768
  • 1
  • 10
  • 24
  • Have you tried changing the `Content Type` to `text/xml` or `application/xml`? See this link for a good description of the difference: http://stackoverflow.com/questions/3272534/what-content-type-value-should-i-send-for-my-xml-sitemap – RocketDonkey Dec 04 '12 at 02:08
  • I tried both text/xml and application/xml. All of these are just making xml text show up on browser. The answer to [this question](http://stackoverflow.com/questions/2767910/google-app-engine-python-download-file) suggests using text/csv as a content-type. That makes the file downloadable, but the extension isn't xml. But thanks anw. – AzaFromKaza Dec 04 '12 at 02:19
  • 3
    And have you messed around with the `Content Disposition` itself? Something like `self.response.headers['Content-Disposition'] = 'attachment; filename=myfile.xml'`? This should force the `Save As` dialog, I believe. – RocketDonkey Dec 04 '12 at 02:24
  • Awesome, good to hear! Good luck with everything. – RocketDonkey Dec 04 '12 at 02:29

0 Answers0