Download file in python on clicking on href

72 Views Asked by At

I am trying to click on below href link.

href="javascript:;"

<div class="xlsdownload">
<a id="downloadOCTable" 
    download="data-download.csv"
    href="javascript:;" 
    onclick="downloadOCFile(this, 'equity')">
    <img src="/assets/images/icon-xls.svg" alt="csv" title="csv" >
    Download (.csv)
</a>
</div>

How to click on this event?

1

There are 1 best solutions below

0
Pandurang Choudekar On

Use following code if you using flask

from urllib import request
from flask import send_from_directory

@app.route('/download_file')
def download_file():
   file_name = 'document_template.xltx'
   wb = load_workbook('document.xlsx')
   wb.save(file_name, as_template=True)
   return send_from_directory(file_name, as_attachment=True)