【发布时间】:2022-01-01 01:38:35
【问题描述】:
在 python 脚本在后台成功后,我试图通过烧瓶重定向到外部站点(例如:google.com)。我不确定如何同时重定向和呈现模板。
这是烧瓶代码:
@app.route ("/result",methods=['POST','GET'])
def result():
if request.method == "POST":
ip1=request.form.get('ip')
output=subprocess.getstatusoutput(["ping -c 2 " +str(ip1)])
out=output[1]
ec=output[0]
return render_template("home.html",out=output[1])
sleep(3) // Time given so that the output of ping command above gets printed in html page
return redirect ("http://www.google.com/",code=307) // Sample External site
The above code works till rendering the page "home.html" and prints the output from "ping" command , but doesn't redirect upon successful execution . Is there a way where we can get the redirect based on the exit code of a command's success or show a failure message on error exit code
【问题讨论】:
标签: python html flask redirect