我有一个 HTML 代码,其中有一个“下载”按钮,可以通过 GET 将文件下载到 python 代码,问题是该页面的刷新率为 5 秒,并且运行良好,但是一旦我单击下载按钮文件下载完毕后,页面停止刷新。
我能做什么来修复它?
HTML:
<html>
<meta http-equiv="refresh" content="5">
<style>
mark {
background-color: grey;
color: white;
}
</style>
<title>{{client}}</title>
<form target="_parent" method="get" action="download_file" style="display: inline;">
<h4><mark>{{client}}</mark></h4>
<br>
<br>
<button onclick="openNav()">download</button>
<input type=hidden name="client" value="{{client}}">
<input type=hidden name="reason" value="{{reason}}">
</form>
</body>
<script>function openNav() {
document.getElementById("myNav").style.width = "100%";
}
</script>
</html>
Python:
@app.route("/download_file", methods=["GET"])
def download_file():
#a lot of code to get the file
response = flask.Response(output, mimetype="zip", headers={"Content-disposition":"attachment; filename="+ randomName + ".zip"})
return response
已尝试添加onclick按钮,但"window.location.reload();"不执行任何操作,它会等到文件下载完成并且页面失去刷新选项,直到我在页面上使用 F5 手动执行此操作
婷婷同学_
相关分类