Ananda  Shankar Das Ananda Shankar Das - 1 month ago 6
Python Question

create button in main page to redirect to a response function

I have a csv file in a server. I have created a response function to download it in the users browser. It work fine. Now I need to create a button in the main index.html and create a response function so that file gets downloaded on clicking it. I just need the download , no redirect to new page required

@app.route('/csv/')
def download_csv():
csv = p
response = make_response(csv)
cd = 'attachment; filename=RosterUnified.csv'
response.headers['Content-Disposition'] = cd
response.mimetype='text/csv'

return response

Answer

Your question is quite confusing, but if you are simply asking for a button to download the file without making the browser leave the current page:

<a href="/csv/" download>Download the file</a>

This creates a link which you can style in CSS to appear like a button. Please tell me if I misunderstood the question.