You could use a return
statement and return a string format.
As the <redirect url>
you could set any URL from available to your back-end.
This solution is similar to dmitrybelyakov's, but it's a quick fix without having to deal with new, small html templates.
return f"<html><body><p>You will be redirected in 3 seconds</p><script>var timer = setTimeout(function() {{window.location='{ <redirect url> }'}}, 3000);</script></body></html>"
Example:
Lets say you want to submit a form and have a run time issue that requires you to do this redirect after a certain time.
@app.route('/')
def your_func():
form = FormFunc()
if form.validate_on_submit():
# do something
wait_time = 3000
seconds = wait_time / 1000
redirect_url = 'https://www.example.com/'
# if the validation is successful, forward to redirect page, wait 3 seconds, redirect to specified url
return f"<html><body><p>You will be redirected in { seconds } seconds</p><script>var timer = setTimeout(function() {{window.location='{ redirect url }'}}, { wait_time });</script></body></html>"
# if the validation is not successful, reload the form
return render_template('formPage.html', form=form)