I've got most of finance working but I can't for the life of me sort out /check. No matter what 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.'

Here's my html:

<form action="/register" method="post" id="myForm">
    <div class="form-group">
        <input autocomplete="off" autofocus class="form-control" id="username" name="username" placeholder="Username" type="text">
    <div class="form-group">
        <input class="form-control" id="password" name="password" placeholder="Password" type="password">
    <div class="form-group">
        <input class="form-control" id="confirmation" name="confirmation" placeholder="Confirm password" type="password">
    <button class="btn btn-primary" type="submit" name="btnSubmit" id="btnSubmit">Register</button>

Here's my JS:

    $('#myForm').submit(function(event) {
        /* alert("Default prevented"); */
        let username = $("#username").val();
        $.get('/check?username=' + username, function(data) {
            if(data == false) {
                alert("Username taken.");
            else {
                console.log("Username free.");

Here's my python (not yet fully implemented - but should be returning a value!):

@app.route("/check", methods=["GET"])
def check():
"""Return true if username available, else false, in JSON format"""

# If request made via GET
if request.method==["GET"]:

    # Takes username as argument from username
    username = request.args.get('username')

    # If not user, then username is free
    users = db.execute("SELECT username FROM users WHERE username=:username", username=username)
    if not users:
        return jsonify(True)
        return jsonify(False)

if request.method==["GET"]:

That should be if request.method=="GET":

alternatively, remove it entirely, since you've already said that the function is only valid for a GET: @app.route("/check", methods=["GET"])

  • D'oh, can't believe it was something so silly, I was staring at it for hours! Thank you! Fixed that, encountered a whole bunch of new bugs and fixed them, now I've FINALLY submitted Finance :D – user23081 Mar 28 '19 at 12:33
  • struggling with this myself, what other bugs did you fix? – Tomás Morell May 2 '19 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .