Yes, I know this is similar to other questions, but the Brython syntax and functions are so much different that their solutions aren't applicable here.
After doing a successful post with Ajax, the webpage is not redirecting to what Flask tells it to. The print statement in the first code snippet executes and prints the value from the HTML, and Flask debugging tells me that there was a get request for success.html (the redirect), but the webpage does not redirect. Here is my code:
@app.route("/test", methods=["POST", "GET"])
def testing():
if request.method == "POST":
print(request.values["test"])
return redirect(url_for("success"))
else:
return render_template("test.html")
And the HTML:
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<title>Testing</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.8.9/brython.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/brython@3.8.9/brython_stdlib.js"></script>
<body onload="brython()">
<script type="text/python">
from browser import ajax
ajax.post(url="{{ url_for('testing') }}", data={"test": "this is a test"})
</script>
</body>
</html>
Here is the debugging from the console:
127.0.0.1 - - [14/May/2021 18:31:08] "GET /test HTTP/1.1" 200 -
this is a test
127.0.0.1 - - [14/May/2021 18:31:10] "POST /test HTTP/1.1" 302 -
127.0.0.1 - - [14/May/2021 18:31:10] "GET /success HTTP/1.1" 200 -
What should I do to make it redirect successfully?