问题描述
我正在Flask网站上工作,
视频开始下载,下载完成后,应调用一个函数,该函数会将用户重定向到另一页面。
.download_complete(function)
在成功下载视频后运行,并且运行带有args详细信息和文件路径的功能
def redirectTheUser(details,filepath):
-Some code that should redirect user-
@app.route("/download")
def download():
-some code -
yt.download_complete(redirectTheUser)
解决方法
我终于能够找出我该怎么办:
所以,如果下载完成变量(使用jinja vars)为true,则我现在正在重定向但使用Javascript
Py文件
downloadStatus = False
#By default download status will be False
def redirectUser(self,filepath):
global downloadStatus
downloadStatus = True
@app.route("/download")
def download():
yt.download_complete(redirectUser)
global downloadStatus
return render_template("download.html",downloadStatus = downloadStatus)
download.html文件
<HTML>
........
<body>
....
<script>
downloadComplete = "{{ downloadStatus }}"
if (downloadComplete == "True"){
window.location.replace("--redirevt your user--")
}
</script>
</body>
</html>