I have implemented Pset-7 (Finance) but check50 shows an error called expected 400 but got 200 in all my apology pages and it is being rejected by check50. Since it successfuly landed to apology page, i think it is obvious to give 200 OK, Can anyone explain it to me?
My register.py:
@app.route("/register", methods=["GET", "POST"])
def register():
"""Register user"""
# checking if post method have been used
if request.method == "POST":
# checking if user has entered username
if not request.form.get("username"):
return apology("must provide username",400)
# Ensure password was submitted
if not request.form.get("password"):
return apology("must provide password", 400)
# Ensure confirmation was submitted
if not request.form.get("confirmation"):
return apology("must provide password twice", 400)
# Ensure both password and confirmation are same
if request.form.get("password") != request.form.get("confirmation"):
return apology("passwords don't match", 400)
# hashing password
hash = generate_password_hash(request.form.get("password"))
# adding username to database
result = db.execute("INSERT INTO users (username,hash) VALUES(:username, :hash)",
username = request.form.get("username"), hash=hash )
# if result is not successful then this means username already exists
if not result:
return apology("username already exists", 400)
# storing id in session
rows = db.execute("SELECT * FROM users WHERE username = :username ",
username = request.form.get("username"))
session["user_id"] = rows[0]["id"]
# Redirect user to home page
return redirect("/")
else:
#giving login page to users using get method
return render_template("register.html")
My 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 %}