I am getting an Internal Server error whenever I click on "Register"... However, the terminal window points me to a line that is not part of my code (this section:

def errorhandler(e):
    """Handle error"""
    return apology(e.name, e.code)

) Below I have attached my server log. Thank you!

    @app.route("/register", methods=["GET", "POST"])
def register():
    """Register user"""
    if request.method == "POST":

        if not request.form.get("username"):
            return apology("MISSING USERNAME", 403)
        if not request.form.get("password"):
            return apology("MISSING PASSWORD", 403)
        if not request.form.get("confpassword"):
            return apology("MISSING PASSWORD CONFORMATION", 403)
        if request.form.get("password") != request.form.get("confpassword"):
            return apology("PASSWORDS DO NOT MATCH", 403)
        hash = generate_password_hash("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 TAKEN", 403)

        session["user_id"] = result[0]["user_id"]

        return redirect("/")

enter image description here


Unless you omitted the else: part, for a GET request, your function does not return anything. Make it return a rendered page in that case.

BTW, make sure to study https://docs.cs50.net/2018/x/psets/7/finance/finance.html#hints (and especially what db.execute returns in each case)

You must log in to answer this question.

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