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")
            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"]
                return apology("Username already exists")

            return redirect("/")


    {% extends "layout.html" %}

    {% block title %}
    {% 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 class="form-group">
                <input class="form-control" name="password" placeholder="Password" type="password">
            <div class="form-group">
                <input class="form-control" name="confirmation" placeholder="Password (again)" type="password">
            <button class="btn btn-primary" type="submit">Register</button>
    {% endblock %}


    {% extends "layout.html"}
    {% block title %}
    {% endblock %}
    {% block main %}
        <table class="table table-striped">
                    <td colspan="4"></td>
                    <td>{{ grand_total }}</td>
                {% for holding in holdings %}
                    <td>{{ holding["symbol"] }}</td>
                    <td>{{ holding["name"] }}</td>
                    <td>{{ holding["shares"] }}</td>
                    <td>{{ holding["price"] }}</td>
                    <td>{{ holding["total"] }}</td>
                {% endfor %}
                    <td colspan="4"></td>
    {% endblock %}
  • Can you please share your index.html
    – Vsjain
    Feb 15 at 11:51
  • Just added it! @Vsjain
    – yatoe
    Feb 15 at 13:16

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.

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

You must log in to answer this question.

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