When I hit refresh on a page with flash message already showing, the message persist even after the refresh. How do I stop the message from showing on refresh? I noticed when I use render_template
after flash
the flash message will persist, but when I use redirect
it doesn't. However I have to pass a non-3xx status code when I flash a message, using redirect
only gets user wait on a redirection page until further action, which is not desirable either.
Method 1: Shows the right page but message persists on refresh:
flash("An error occurred.")
return render_template("page.html"), 400
Method 2: Stuck on redirection page but message doesn't persist on refresh:
flash("An error occurred.")
return redirect(url_for('show-page'), code=400)
Redirecting... You should be redirected automatically to target URL: /page. If not click the link.
Method 2 does work as I intended if I pass a 3xx code, but I need to pass non-3xx code.
Note: The user should be on the same page throughout.