0

I have been working on this for a long time, and it still is giving me an error message saying that a letter s is the only reason for all of my problems. Here is my code in Flask.

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

    if not request.form.get("username"):
        return apology("must provide username!")


    elif not request.form.get("password"):
        return apology("must provide password")


    elif not request.form.get("confirm"):
        return apology("must provide password confirmation")

    elif request.form.get("password") != request.form.get("confirm"):
        return apology("Sorry, password didn't match. Try Again!")
    hashed_password = generate_password_hash(request.form.get("password"))

    db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)",
            username = request.form.get("username"),
            hash = hashed_password

    rows = db.execute("SELECT * FROM users WHERE username = :username",
              username = request.form.get("username"))

    session["user_id"] = rows[0]["id"]

    return redirect("/")


else:
    return render_template("register.html")

And here is my code in register.html.

{% extends "layout.html" %}

{% block title %}
 Register
{% endblock %}

{% block main %}
    <form action="/register" method="post">
    <div class="form-group">
        <input autocomplete="off" autofocus class="form-control" 
 name="username" placeholder="Username" type="text"/>
    </div>
    <div class="form-group">
        <input class="form-control" name="password" placeholder="Password" 
 type="password"/>
    </div>
    <div class="form-group">
        <input class="form-control" name="confirm" 
 placeholder="Password (again)" type="password"/>
    </div>
    <button class="btn btn-primary" type="submit">Register</button>
</form>
{% endblock %}

Can somebody please help me? I don't understand what the bug is, but there is always something. And can you do it quickly?

4
  • What does this error mean?
    – NoahRS
    May 4 '20 at 17:19
  • I got it to work but this happens:
    – NoahRS
    May 4 '20 at 17:20
  • ERROR:application:Exception on /register [POST]
    – NoahRS
    May 4 '20 at 17:20
  • It looks like you're missing a close paren at this line: db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username = request.form.get("username"), hash = hashed_password <---. This might be causing some issues as well
    – azb1297
    May 4 '20 at 18:20

You must log in to answer this question.

Browse other questions tagged .