0

I'm struggeling with this bug for several days now and don't know how to fix it. I didn't find an answer in all the previous questions.

Except my personal touch I finished pset7. If I start flask everything works just fine but if I do check50 I get this error message:

enter image description here

I don't really understand how there can be an 400 error when it's working with flask. If I check in the chrome developer tools or the terminal I can also see no errors. I know that if you call "return apology("text") it will return an 400 Error but I don't call it here. Do I need to change some lines in helpers.py? And also I don't understand why the expected status code of "registration rejects duplicate username" is 200, shouldn't it be 400 because an error will occur? I am not sure if my bug is in the register part of application.py but I will post it here anyway. I would be really thankful if you can have a look at my code and maybe give me a hint where I can look for my bug. Thank you very much in advance.

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user"""
# User reached route via POST (as by submitting a form via POST)
if request.method == "POST":

    # Ensure username was submitted
    if not request.form.get("username"):
        return apology("Missing username")

    # Ensure password was submitted
    elif not request.form.get("password"):
        return apology("Missing password")

    # Ensure password was confirmed
    elif not request.form.get("confirmation"):
        return apology("Missing password confirmation")

    # Ensure password and confirmation match
    elif request.form.get("username") != request.form.get("confirmation"):
        return apology("The passwords do not match! Please Try again")

    hash = generate_password_hash(request.form.get("password"), method='pbkdf2:sha256', salt_length=8)

    result = db.execute("INSERT INTO users (username, hash) VALUES (:username, :hash)", username = request.form.get("username"), hash = hash)

    if not result:
        return apology("The username is already taken")

    rows = db.execute("SELECT * FROM users WHERE username = :username",
                      username = request.form.get("username"))

    # Remember which user has registered
    session["user_id"] = rows[0]["id"]

    # Redirect user to home page
    return redirect(url_for("index"))

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("register.html")

2 Answers 2

1

Your register code gives me all greens when I run check50 with it.

Have you looked at the URL that check50 gives you to see more details about the tests that are failing? It may be a problem with your finance.db or your templates.

1
  • Thanks for your answer! I already found the bug. I swapped username & password once... I will close this question now. Have a great day! Mar 14, 2018 at 0:08
0

Check your last elif statement. You have a mistake there:) Hope this is the issue.

You must log in to answer this question.

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