0

I trying using Brython with Ajax imported to test ajax.post. When I do, I get the error "TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement." in my server console and the error "Failed to load resource: the server responded with a status of 500 (INTERNAL SERVER ERROR)" in the developer webpage console. My code is:

@app.route("/test", methods=["POST", "GET"])
def testing():
    if request.method == "POST":
        print(request.args.get("test", 0, type=str))
    else:
        return render_template("test.html")

and

<!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="http://localhost:5000/test", data={"test": "work pls"})
        </script>
    </body>
</html>

How do I prevent these errors from happening and have a successful ajax post?

Edit: Fixed errors but now it is not printing the right thing

  • When the request method is `POST` you're simply printing and not returning anything, as the error states. – Phix May 13 '21 at 19:17
  • @Phix Oh, thanks. But now it is printing 0 or None depending on whether or not I have the "0" argument in request.args.get – Hairline_Bandit May 13 '21 at 19:22

0 Answers0