When im testing my code by entering in blank entries in username or password, i expect the site to show me the apologies like "Must provide username" or "Must provide password", but it only shows the apology "Sorry!" each time, and the picture does not display either. Anyone knows what I am doing wrong?

Here is my code

@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user."""

if request.method=="POST":

    # Make sure username was submitted
    if not request.form.get("username"):
        return apology("Must provide username")

    # Make sure password was submitted
    elif not request.form.get("password"):
        return apology("Must provide password")

    # Make sure passwords match
    elif request.form.get("password")!= request.form.get("passwordconfirm"):
        return apology("Passwords do not match")

    # Store the user in the table users and hash his/her password
    result = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash =pwd_context.encrypt(request.form.get("password")))

    if not result:
        return apology("Username already exist")

    # Remember which user has logged in
    session["user_id"] = result

    # Redirect user to home page
    return redirect(url_for("index"))

    return render_template("register.html")

Here is my HTML code:

{% extends "layout.html" %}

{% block title %}
{% endblock %}

{% block main %}
    <form action="{{ url_for('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="passwordconfirm" placeholder="Password confirm" type="password"/>
            <div class="form-group">
                <button class="btn btn-default" type="submit">Register</button>
{% endblock %}
  • Just to be sure, you haven't altered apology.html or helpers.py?
    – curiouskiwi
    Sep 4, 2017 at 2:18
  • The "Sorry!" is the alt attribute of the image. You can change it by replacing alt="Sorry!" for example with alt="{{ top }} {{ bottom}}" to see the actual message even if the image won't load. The meme generator has been slow recently, have you waited for a while?
    – Blauelf
    Sep 4, 2017 at 9:28
  • I have not altered apology.html or helpers.py. Should I ?
    – L.D
    Sep 4, 2017 at 22:20
  • I thought that the apology messages that I wrote in application.py was going to be passed to the apology.html file, and then displayed to the user when he/she types in invalid username/password etc.. But then I need to replace the "Sorry!" message in apology.html with a variable?
    – L.D
    Sep 4, 2017 at 22:24

1 Answer 1


check for the indentation of the register() function.

  • This is most likely a mistake in posting the code here. Python would complain about a function definition containing no code at all (not even pass, the no-op).
    – Blauelf
    Oct 11, 2017 at 9:55

You must log in to answer this question.

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