I was able to figure out the POST and /register, but I am confused on how to use INSERT a new user into users. Any help would be appreciated. Thank you.

From application.py

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

From register.html

 <div class="form-group">
            <input class="form-control" name="password" placeholder="Password" type="password">
        <div class="form-group">
            <input class="form-control" name="confirmation" placeholder="Password Again" type="password">
  • Have you taken a username also?
    – Vsjain
    Oct 8, 2020 at 7:55
  • Yes I have a username: <div class="form-group"> <input autocomplete="off" autofocus class="form-control" name="username" placeholder="Username" type="text"> </div> Oct 8, 2020 at 15:01

1 Answer 1


One approach would be to combine the skills learned

  • in the Flask video starting around minute 42. That demonstrates how to get data from a form and "use" it in a function (the add function in this case).

  • in pset7:houses for inserting data into a database.

  • Thank you for the tip! I am closer with the following code: @app.route("/register", methods=["GET", "POST"]) def register(): if request.method == "GET": return render_template("register.html") else: username = request.form.get("username") password = request.form.get("hash") db.execute("INSERT INTO users (username, hash) VALUES (:username, :hash)", username = request.form.get("username"), hash = generate_password_hash(request.form.get("password")) return redirect("/") However, I get an error message: Oct 9, 2020 at 22:30
  • Can you please help? The error message is: File "/home/ubuntu/pset8/finance/application.py", line 129 return redirect("/") ^ SyntaxError: invalid syntax Oct 9, 2020 at 22:32
  • SyntaxError comes from the parser. Probably unbalanced something, parens? quotes? FWIW Block of code in a comment is not good SE style, especially white-space dependent Python. Oct 10, 2020 at 11:14
  • Thank you for the tip. I'll see if I can figure it out. FWIW, I couldn't figure out how to format the code in the comment as I did in the original question above. In the code, I have a new line for if, return, else, etc. Oct 10, 2020 at 14:29
  • Strictly speaking, it should be a new question. There is not a way to format code in comments, (save one-liners, which can be enclosed in back-ticks `), because comments is not the place for code blocks. It could be edited into the question and formatted, but in this case, it changes the whole meaning of the question. Oct 10, 2020 at 14:48

You must log in to answer this question.

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