I'm attempting to redirect to an external site (ex: google.com) via flask after a python script succeeds in the background. i'm not sure how to redirect and render a template at the same time .
Here's the flask code:
@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