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)