0

I'm getting a Error 500 (-Internal error due to server overload) when I attempt to flask run for pset8-Finance.

Here is my app.route("/register")

    @app.route("/register", methods=["GET", "POST"])
def register():
   if request.method == "POST":
        """Register user"""
        #Check for entered username and password
        if not request.form.get("username"):                    #get username
            return apology("Please enter a username.")          #if username is blank
        elif not request.form.get("password"):                  #get password - first attempt
            return apology("Please provide a password.")        # if password is blank
        elif request.form.get("password") != request.form.get("confirmation"):  #get password - second attempt
            return apology("These passwords do not match.")     #if password and confirmation do not match

        # Hash password as per specs
        hash = generate_password_hash(request.form.get("password"))
        username = request.form.get("username")
        new_user = db.execute("INSERT INTO users (username, hash)

        #if not new_user:
            #return apology("That username is taken, please choose another.")

        session["user_id"] = new_user
        sflash("You have successfully registered!")
        return redirect(url_for("index"))
    else:
        return render_template("register.html")
0

1 Answer 1

0

The log generated in the flask run console is your friend. It should direct your attention to this line new_user = db.execute("INSERT INTO users (username, hash) It is an incomplete thought.

[Additional info based on comments]

This
assets = db.execute("SELECT cash FROM users WHERE user_id =:user_id, id=session["user_id"])
is incorrect syntax. There is a close " missing (for the query text). Since :user_id is the placeholder, the substitution argument would be user_id=session["user_id"]

4
  • Hmmmm... I'm being directed to File "/home/ubuntu/finance/application.py", line 60 assets = db.execute("SELECT cash FROM users WHERE user_id =:user_id, id=session["user_id"]) where user_id has a carat under it. I switched it to id (since user_id) doesn't exist in the users table. No love. I switched the used_id:=user_id around a bit. Nothing.....I'm not seeing my mistake. Thanks for trying to help.
    – KayO133
    Dec 18, 2019 at 8:11
  • Answer has been amended. Dec 18, 2019 at 13:07
  • Same issue after being rewritten as: assets = db.execute("SELECT cash FROM users WHERE user_id=:user_id, id=session["user_id"]")
    – KayO133
    Dec 21, 2019 at 10:31
  • This id=session["user_id"]") is still incorrect.Since :user_id is the placeholder, the substitution argument would be user_id =session["user_id"]. And there is a missing close " for the query text. Dec 21, 2019 at 11:43

You must log in to answer this question.

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