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"))
else:
return render_template("register.html")
Here is my HTML code:
{% extends "layout.html" %}
{% block title %}
Register
{% endblock %}
{% block main %}
<form action="{{ url_for('register') }}" method="post">
<fieldset>
<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="passwordconfirm" placeholder="Password confirm" type="password"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">Register</button>
</div>
</fieldset>
</form>
{% endblock %}
alt
attribute of the image. You can change it by replacingalt="Sorry!"
for example withalt="{{ 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 '17 at 9:28