0

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 %}
2
  • Can you please share your index.html
    – Vsjain
    Commented Feb 15, 2021 at 11:51
  • Just added it! @Vsjain
    – yatoe
    Commented Feb 15, 2021 at 13:16

1 Answer 1

0

The TemplateSyntaxError was taking place in your index.html file. In the first line, your curly brackets haven't been closed properly. You started with {% and ended the tag with } for extending layout.html. Just fix that and the test should pass.

Hope this helps. If it does, then please check the tickmark.

1
  • lol you're right! thank you :)
    – yatoe
    Commented Feb 15, 2021 at 14:24

You must log in to answer this question.

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