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
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