Sometimes, we want to download a csv file on clicking a button with Python Flask.
In this article, we’ll look at how to download a csv file on clicking a button with Python Flask.
How to download a csv file on clicking a button with Python Flask?
To download a csv file on clicking a button with Python Flask, we can create a route that returns the csv file.
For instance, we write
from flask import send_file
@app.route("/get-plot-csv")
def plot_csv():
return send_file(
"outputs/Adjacency.csv",
mimetype="text/csv",
attachment_filename="Adjacency.csv",
as_attachment=True,
)
to call send_file
with the file path, mimetype
, attachment_filename
, and as_attachment
set to True
to return a csv file response.
We set the MIME type to 'text/csv'
and the download file’s filename is Adjacency.csv.
Conclusion
To download a csv file on clicking a button with Python Flask, we can create a route that returns the csv file.
Popular Posts
- Show / Hide div based on dropdown selected using jQuery
- Autosuggestion Select Box using HTML5 Datalist, PHP and MySQL with Example
- Infinite Scrolling on PHP website using jQuery and Ajax with example
- Custom Authentication Login And Registration Using Laravel 8
- How to Convert MySQL Data to JSON using PHP
- Google Login or Sign In with Angular Application
- 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,452