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():
You can try the following method(python3.6.2):
case one:
@app.route('/hello')
def hello():
headers={ 'content-type':'text/plain' ,'location':'http://www.stackoverflow'}
response = make_response('hello world
',301)
response.headers = headers
return response
case two:
@app.route('/hello')
def hello():
headers={ 'content-type':'text/plain' ,'location':'http://www.stackoverflow.com'}
return 'hello world
',301,headers
I am using Flask .And if you want to return json,you can write this:
import json #
@app.route('/search/')
def search(keyword):
result = Book.search_by_keyword(keyword)
return json.dumps(result),200,{'content-type':'application/json'}
from flask import jsonify
@app.route('/search/')
def search(keyword):
result = Book.search_by_keyword(keyword)
return jsonify(result)