I keep getting an Internal Server Error after trying to register and I don't think I am storing the user ID correctly. Please can someone tell me what I'm doing wrong.

# 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("must provide username", 403)

    # Ensure password was submitted
    elif not request.form.get("password"):
        return apology("must provide password", 403)

    # Ensure password confirmation was submitted
    elif not request.form.get("confirmation"):
        return apology("must confirm your password", 403)

    if not request.form.get("password") == request.form.get("confirmation"):
        return apology("your passwords don't match", 403)

    hash = generate_password_hash(request.form.get("password"))

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

    if not result:
        return apology("username already exists")

    session["user_id"] = result["id"]

    return render_template("register.html")

At a quick read, the problem appears to be that the register function doesn't "return" after the user record is created.

You would see an error like this ValueError: View function did not return a response in your flask terminal.

You must log in to answer this question.

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