I have been stuck on this for a while now. No matter how I change my code nothing works it's the same 3 errors. I think the issue is in my register.html but I can't find anything wrong with it. Here are the errors I get in check50:
:( registering user succeeds application raised an exception (rerun with --log for more details) Log sending POST request to /register exception raised in application: TemplateSyntaxError: expected token ',', got 'string'
:( /check route confirms whether username is available application raised an exception (rerun with --log for more details) Log sending GET request to /check?username=check50student1 checking that status code 200 is returned... sending POST request to /register exception raised in application: TemplateSyntaxError: expected token ',', got 'string'
:( registration rejects duplicate username application raised an exception (rerun with --log for more details) Log sending POST request to /register exception raised in application: TemplateSyntaxError: expected token ',', got 'string'
Here is my register code: ``@app.route("/register", methods=["GET", "POST"]) def register(): """Register user"""
if request.method == "POST":
# Enter username
if not request.form.get("username"):
return apology("must provide username")
# Enter password
elif not request.form.get("password"):
return apology("must provide password")
# Confirm password
elif not request.form.get("password") == request.form.get("confirmation"):
return apology("passwords do not match")
# Hash password and enter into database
hash = generate_password_hash(request.form.get("password"))
new_user = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)",
username=request.form.get("username"), hash=hash)
# Username unique
if not new_user:
return apology("username taken")
session["user_id"] = new_user
flash("Registered!")
return redirect(url_for("index"))
else:
return render_template("register.html")``
Here is my register.html code:
> {% extends "layout.html" %}
>
> {% block title %}
> Register {% endblock %}
>
> {% block main %}
> <script>
> $(document).ready(function(){
> $('#myForm').submit(function(event) {
> event.preventDefault();
> let username = $("#username").val();
> $.get('/check?username=' + username, function(data) {
> if(data == false) {
> alert("Username taken.");
> }
> else {
> console.log("Username free.");
> $('#myForm').submit();
> }
> });
> });
> });
> </script>
> <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 %}
Here is my code for index:
@app.route("/")
@login_required
def index():
"""Show portfolio of stocks"""
# Lookup users
users = db.execute("SELECT cash FROM users WHERE id = :user_id", user_id=session["user_id"])
stocks = db.execute(
"SELECT symbol, SUM(shares) as total_shares FROM transactions WHERE user_id = :user_id GROUP BY symbol HAVING total_shares > 0", user_id=session["user_id"])
quotes = {}
for stock in stocks:
quotes[stock["symbol"]] = lookup(stock["symbol"])
cash_left = users[0]["cash"]
total = cash_left
return render_template("portfolio.html", quotes=quotes, stocks=stocks, total=total, cash_left=cash_left)
And here is my portfolio.html:
{% extends "layout.html" %}
{% block title %}
Quote
{% endblock %}
{% block main %}
<table class="table table-striped">
<thead>
<tr>
<td>Symbol</td>
<td>Shares</td>
<td>Price</td>
<td>Actions</td>
<td>Total</td>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="4"></td>
<td>{{ cash_left | usd }}</td>
</tr>
</tfoot>
<tbody>
{% for stock in stocks %}
<tr>
<td>{{ stock.symbol }}</td>
<td>{{ stock.total_shares }}</td>
<td>{{ quotes[stock.symbol]["price] | usd }}</td>
<td>
<form action="/buy" method="post">
<input type="hidden" name="symbol" value="{{ stock.symbol }}">
<input type="number" name="shares" min="1" placeholder="0" required/>
<button class="btn btn-sm btn-primary" type="submit">Buy</button>
</form>
<form action="/sell" method="post">
<input type="hidden" name="symbol" value="{{ stock.symbol }}">
<input type="number" name="shares" min="1" placeholder="0" required/>
<button class="btn btn-sm btn-primary" type="submit">Sell</button>
</form>
</td>
<td>{{ (quotes[stock.symbol]["price] * stock.total_shares) | usd }}</td>
</tr>
{% endfor %}
<tr>
<td colspan="4">Cash</td>
<td>{{ total| usd }}</td>
</tr>
</tbody>
</table>
{% endblock %}```
index
, or its template, for some reason?