I'm passing all register checks except for:
- :( registering user succeeds
- :( registration rejects duplicate username
I've checked other answers and I've re-written the code a few times but I can't seem to find the issue... the exact check50 message is:
sending POST request to /register
exception raised in application: TemplateSyntaxError: unexpected '}'
I've already checked in all my files that every { is closed with }, that every variable is being passed in inside html's correctly like {{ example }} and also with the blocks {% like this %}. I don't see any issue with the SQL queries either...
register function:
def register():
if request.method == "GET":
return render_template("register.html")
else:
if not request.form.get("username"):
return apology("Please input a username", 400)
if not request.form.get("password") or not request.form.get("confirmation"):
return apology("Please input a password or its confirmation", 400)
if request.form.get("password") != request.form.get("confirmation"):
return apology("Passwords must match", 400)
userr = db.execute("SELECT username FROM users WHERE username = :username", username=request.form.get("username"))
if len(userr) == 0:
db.execute('INSERT INTO "users" ("id","username","hash") VALUES (NULL, :username, :hashed_pword)', username=request.form.get("username"), hashed_pword=generate_password_hash(request.form.get("password")))
the_key = db.execute("SELECT id FROM users WHERE username= :username", username=request.form.get("username"))
session["user_id"] = the_key[0]["id"]
else:
return apology("Username already exists")
return redirect("/")
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="confirmation" placeholder="Password (again)" type="password">
</div>
<button class="btn btn-primary" type="submit">Register</button>
</form>
{% endblock %}
index.html:
{% extends "layout.html"}
{% block title %}
Portfolio
{% endblock %}
{% block main %}
<table class="table table-striped">
<thead>
<tr>
<th>Symbol</th>
<th>Name</th>
<th>Shares</th>
<th>Price</th>
<th>Total</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4"></td>
<td>{{ grand_total }}</td>
</tr>
</tfoot>
<tbody>
{% for holding in holdings %}
<tr>
<td>{{ holding["symbol"] }}</td>
<td>{{ holding["name"] }}</td>
<td>{{ holding["shares"] }}</td>
<td>{{ holding["price"] }}</td>
<td>{{ holding["total"] }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="4"></td>
<td>{{cash}}</td>
</tr>
</tbody>
</table>
{% endblock %}