Python重定向(有延迟) [英] Python redirect (with delay)
本文介绍了Python重定向(有延迟)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我在烧瓶上运行了这个python页面.直到我想要重定向之前,它都可以正常工作.
So I have this python page running on flask. It works fine until I want to have a redirect.
@app.route("/last_visit")
def check_last_watered():
templateData = template(text = water.get_last_watered())
return render_template('main.html', **templateData)
return redirect(url_for('new_page')) #with a delay here of 3 secs
该站点工作正常,但无法重定向,而且我不知道如何延迟整个过程.想法...请:-)
The site works fine, but does not redirect and I wouldn't know how to delay the whole thing. Ideas... Please :-)
推荐答案
好吧,您的函数只会返回渲染的模板,而不会到达重定向语句.如果要显示页面,然后在延迟后执行重定向,请在模板中使用javascript重定向:
Well, your function just returns a rendered template and never reaches the redirect statement. If you want to show a page AND then do a redirect after a delay, use a javascript redirect in your template:
@app.route("/last_visit")
def check_last_watered():
templateData = template(text = water.get_last_watered())
templateData['redirect_url'] = url_for('new_page')
return render_template('main.html', **templateData)
然后在您的 main.html
中:
<script>
setTimeout(function(){
window.location.href = '{{redirect_url}}';
}, 2000);
</script>
这篇关于Python重定向(有延迟)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文