I am off a bad start on this pset, I understand the general idea but still having some difficulty, for register I want to return the user to apology("must provide username") for example, and I looked at the login function but my problem is that how to connect the button register to return this page if something went wrong because when I try the code below, if I didn't provide user name for example, it returns me back to the same register page and not to the apology("must provide username") page
Here is my function:
@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user."""
return render_template("register.html")
# forget any user_id
session.clear()
# if user reached route via POST (as by submitting a form via POST)
if request.method == "POST":
# ensure username was submitted
if not request.form.get("username"):
return apology("must provide username")
# ensure password was submitted
elif not request.form.get("password"):
return apology("must provide password")
# ensure password confirmed
elif not request.form.get("confirm password"):
return apology("must confirm your password")
# ensure passwords match
elif request.form.get("confirm password") != request.form.get("password") :
return apology("your passwords must match")
return redirect(url_for("index"))
# else if user reached route via GET (as by clicking a link or via redirect)
else:
return render_template("register.html")
and here is my register.html:
{% 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="confirm password" placeholder="confirm Password" type="password"/>
</div>
<div class="form-group">
<button class="btn btn-default" type="submit">register</button>
</div>
</fieldset>
</form>
{% endblock %}
I just need someone to get me in the right path,, any help is appreciated,, thanks