I get this error in register in pset7/finance when I run check50:
:) application.py exists
:) application starts up
:) register page has all required elements
:( registering user succeeds
expected status code 200, but got 400
:) registration with an empty field fails
:) registration with password mismatch fails
:( registration rejects duplicate username
expected status code 200, but got 400
:) login page has all required elements
In reality, the function works just fine. Here is my code:
@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user."""
if request.method == "POST":
# # ensure username was submitted
# if not request.form.get("username"):
# return apology("Must provide username", 400)
# # ensure password was submitted
# if not request.form.get("password"):
# return apology("Must provide password", 400)
# # ensure password and verified password is the same
# if request.form.get("password") != request.form.get("passwordagain"):
# return apology("password doesn't match", 400)
if request.form.get("username") != True or request.form.get("password") != True or request.form.get("password") != request.form.get("confirmation"):
return apology("retry", 400)
else:
# insert the new user into users, storing the hash of the user's password
result = db.execute("INSERT INTO users (username, hash) \
VALUES(:username, :hash)", \
username=request.form.get("username"), \
hash=pwd_context.hash(request.form.get("password")))
# if not result:
# return apology("Username already exist")
# remember which user has logged in
session["user_id"] = result
# redirect user to home page
return redirect(url_for("index"), 200)
else:
return render_template("register.html")
I've wasted quite some time on this, and am really stuck. Thanks in advance!