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.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Custom Authentication Login And Registration Using Laravel 8
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Google Login or Sign In with Angular Application
- How to Convert MySQL Data to JSON using PHP
- How to change date format in PHP?
- Image Lazy loading Using Slick Slider
- Slick Slider Basic With Example
- php in_array check for multiple values
- Adaptive Height In Slick Slider
- Slick Slider Center Mode With Example
- How to Scroll to an Element with Vue 3 and ?
- JavaScript Multiple File Upload Progress Bar Using Ajax With PHP
- Slick Slider Multiple Items With Example
Total Views: 1,037