0

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>
    <div class="form-group">
        <input class="form-control" id="password" name="password" placeholder="Password" type="password">
    </div>
    <div class="form-group">
        <input class="form-control" id="confirmation" name="confirmation" placeholder="Confirm password" type="password">
    </div>
    <button class="btn btn-primary" type="submit" name="btnSubmit" id="btnSubmit">Register</button>
</form>

Here's my JS:

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

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)
    else:
        return jsonify(False)
1

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"])

2
  • 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? 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 .