简体   繁体   中英

Flask download file with href

I'm working on web-interface for console applications and I have a table with calculation results.

One column in table contains link to a file on server and i save href in it, smth like

<a href="127.0.0.1:5000/task_id/filename">filename</a>

And i have route in python code it looks like this

@app.route("/<task_id>/<file_name>", methods=['GET', 'POST'])
def getFile(task_id, file_name):
    return send_file(app.config['UPLOAD_FOLDER'] + str(task_id) + '/' + file_name, as_attachment=True)

And when i click on link file i dont get the file but blank page opens. But when i copy-paste the link from href i can download file correctly.

How can i fix it?

I was wrong. Need to use relative link in href so correct version looks like

<a href="task_id/filename">filename</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM