Issue
I am using Flask and I return an XML file from a get request. How do I set the content type to xml ?
e.g.
@app.route('/ajax_ddl')
def ajax_ddl():
xml = 'foo'
header("Content-type: text/xml")
return xml
Solution
Try like this:
from flask import Response
@app.route('/ajax_ddl')
def ajax_ddl():
xml = 'foo'
return Response(xml, mimetype='text/xml')
The actual Content-Type is based on the mimetype parameter and the charset (defaults to UTF-8).
Response (and request) objects are documented here: http://werkzeug.pocoo.org/docs/wrappers/
Answered By - Simon Sapin
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.