Ananda  Shankar Das Ananda Shankar Das - 1 year ago 67
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

def download_csv():
csv = p
response = make_response(csv)
cd = 'attachment; filename=RosterUnified.csv'
response.headers['Content-Disposition'] = cd

return response

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download