Sometimes, we want to set content type with Python Flask.
In this article, we’ll look at how to set content type with Python Flask.
How to set content type with Python Flask?
To set content type with Python Flask, we can use the Response
class.
For instance, we write
from flask import Response
@app.route("/ajax_ddl")
def ajax_ddl():
xml = "foo"
return Response(xml, mimetype="text/xml")
to create a Response
object with the xml
string as the body and the mimetype
set to the MIME type of the response.
Conclusion
To set content type with Python Flask, we can use the Response
class.