0

I almost spent a whole day on this. I saw every letter in the function, but still didn't got any progress. When I register, It show like this

login error

here's my code:

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user"""
    if request.method == 'POST':
            if not request.form.get("username"):
                return apology("Username not included")
            elif not request.form.get("password"):
                return apology("Password not included")
            elif not request.form.get("confirmation"):
                return apology("Password Confirmation not included")
            gen_hash = generate_password_hash(request.form.get("password"))
            db.execute("INSERT INTO users(username, hash) VALUES(?, ?);", (request.form.get("username"), gen_hash, ))
            rows = db.execute("SELECT * FROM users WHERE username = :username;", username=request.form.get("username"))
            if len(rows) != 1:
                return apology("Username already exists")
            session["user_id"] = rows[0]["id"]
            return redirect("/")
    elif request.method == 'GET':
            return render_template("register.html")

register.html(using jinja):

{% extends "layout.html" %}

{% block title %}
    Log In
{% endblock %}

{% block main %}
    <form action="/login" 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="confirmation" placeholder="Confirm Password" type="password">
        </div>
        <button class="btn btn-primary" type="submit">Register</button>
    </form>
{% endblock %}

please help

6
  • suspect the problem is in register.html: check the action attribute of form element. Is it pointing to "login"? – DinoCoderSaurus Nov 30 '20 at 15:24
  • Ok I'll check, but is the register code correct? – Trisanu Das Nov 30 '20 at 15:58
  • Yes it is pointing to login. So what to do? – Trisanu Das Dec 1 '20 at 3:44
  • And can you please clarify all the mistakes in a whole answer. I have also given the html file, and the "please include confirmation" condition is also not working – Trisanu Das Dec 1 '20 at 4:08
  • please help😿, I don't know why is it not working – Trisanu Das Dec 1 '20 at 11:37
0

Actually, @DinoCoderSaurus was correct. The html file should be like below, not on the above:

{% extends "layout.html" %}

{% block title %}
    Log In
{% 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="confirmation" placeholder="Confirm Password" type="password">
        </div>
        <button class="btn btn-primary" type="submit">Register</button>
    </form>
{% endblock %}

You must log in to answer this question.

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