I've hit a snag when trying to implement register in pset7. Every time I enter a new username, password, and password confirmation, I'm getting a 500 server error. I don't know how to read the log to understand what is creating this error in my code.
I have already looked at a similar question here, but found the answer did not apply to my problem, and I do not have check50 for this problem in the 2018 version of CS50x: How can I debug an internal server error in pset 7 to get past login and register?
Any insight would be appreciated. Thank you for your time!
@app.route("/register", methods=["GET", "POST"]) def register(): # 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", 403) # Ensure password was submitted elif not request.form.get("password"): return apology("missing password", 403) elif not request.form.get("confirmation"): return apology("please confirm your password", 403) elif request.form.get("confirmation") != request.form.get("password"): return apology("passwords do not match", 403) # if all conditions met, store username username=request.form.get("username") # hash password hash = generate_password_hash(request.form.get("password"), method='pbkdf2:sha256', salt_length=8) """Register user""" # check to see if that username already exists in users column result=db.execute("SELECT * FROM users WHERE username = :username") # if user name already exists db.execute fails, so return apology if not result: return apology("sorry, username already exists", 403) # insert username and hashed password, AND create a user_id in session to log in session["user_id"]=db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash=hash) # Redirect user to home page return redirect("/") # User reached route via GET (by clicking a link or via redirect) else: return render_template("register.html")