简体   繁体   English

带有href的Flask下载文件

[英]Flask download file with href

I'm working on web-interface for console applications and I have a table with calculation results. 我正在为控制台应用程序的web界面工作,我有一个包含计算结果的表。

One column in table contains link to a file on server and i save href in it, smth like 表中的一列包含指向服务器上文件的链接,我将href保存在其中,就像

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

And i have route in python code it looks like this 我在python代码中有路由它看起来像这样

@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. 但是当我从href复制粘贴链接时,我可以正确下载文件。

How can i fix it? 我该如何解决?

I was wrong. 我错了。 Need to use relative link in href so correct version looks like 需要在href中使用相对链接,因此正确的版本看起来像

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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