How do I customize the content type of the response in the flask?

I want to be able to return something other than application / json ie kml.

I have the following:

def kml(data):
    return Response(data, mimetype='application/')

class mykml(restful.Resource):

    def get(self):
        r = requests.get("http://myurl/kml") # This retrieves a .kml file   
        response = make_response(r.content)
        response.headers['Content-Type'] = "application/"

        return response


Why is this still returning app / json? Also, if I have different formats, can I dynamically change the Content-Type for the user in the mykml class without a decorator?

Import: from flask import Flask, request, Response, session,make_response


source to share

All Articles