0

I am struggling with the implementation of register. I started small, just copied the content of the already defined login-function as well as the content of login.html. So, my first attempt is just to check if I can insert a new user and the password into the database wihtout the password-confirmation field and without password hashing. My code in application.py:

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user"""
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)

    # insert user into database
    db.execute("INSERT INTO finance (username, hash) VALUES (?, ?)", request.form.get("username"), request.form.get("password"))

    # Redirect user to login page
    return redirect("/login")

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

My template looks like this and is stored in the templates directory:

enter image description here

Edited: Executing this I get a 500 code. The message in the terminal window is RuntimeError: no such table: finance How can that be? The db is implemented in the code and I checked that I don't have a spelling error.

Thanks in advance.

2
  • Review the the traceback in the flask run console. That will give you the information you need to know what error is being produced. If you are not sure what the error means, edit this question and add the traceback. Aug 29 at 20:07
  • Edited the question. I get the message what the error is but I don't no how to fix it because in the code everything seems fine to me
    – Mi-Wa
    Aug 30 at 8:05
0

The name of the database is finance. The name of the (supplied) table is users. This sql

db.execute("INSERT INTO finance.....

is incorrect. The FROM clause refers to a table or subquery.

You must log in to answer this question.

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