0

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

# Forget any user_id
session.clear()

# 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", 400)

    # Ensure password was submitted
    elif not request.form.get("password"):
        return apology("must provide password", 400)

    # Ensure password and confirmation match
    elif request.form.get("password") != request.form.get("confirmation"):
        return apology("passwords don't match", 400)

    # hash the password and insert a new user in the database
    hash = generate_password_hash(request.form.get("password"))

    new_user_id = db.execute("INSERT INTO users (username, hash) VALUES(:username, :hash)",
                             username=request.form.get("username"),
                             hash=hash)

    # unique username constraint violated?
    if not new_user_id:
        return apology("username taken", 400)

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

    # Display a flash message
    flash("Registered!")

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

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("register.html")

return apology("there is a mistake")

@app.route("/login", methods=["GET", "POST"]) def login(): """Log user in"""

# Forget any user_id
session.clear()

# 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", 403)

    # Ensure password was submitted
    elif not request.form.get("password"):
        return apology("must provide password", 403)

    # Query database for username
    rows = db.execute("SELECT * FROM users WHERE username = :username",
                      username=request.form.get("username"))

    # Ensure username exists and password is correct
    if len(rows) != 1 or not check_password_hash(rows[0]["hash"], request.form.get("password")):
        return apology("invalid username and/or password", 403)

    # Remember which user has logged in
    session["user_id"] = rows[0]["id"]

    # Redirect user to home page
    return redirect("login.html")

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("/")

enter image description here

3
  • In pset7 finance I still have this error I feel i'll be stuck here forever, help me please
    – Manal
    Dec 31 '18 at 4:10
  • It is likely the problem is in the register function (since the login function is supplied). Perhaps edit this post and show the register function. Dec 31 '18 at 7:13
  • Thanks for replay... Could you check the register function, please?
    – Manal
    Dec 31 '18 at 15:11
0

The login function in the distribution application.py ends this way:

# Redirect user to home page
     return redirect("/")

 # User reached route via GET (as by clicking a link or via redirect)
 else:
     return render_template("login.html")

The login function pasted here ends this way:

# Redirect user to home page
    return redirect("login.html")

# User reached route via GET (as by clicking a link or via redirect)
else:
    return render_template("/")

This login function causes check50 to fail at the second test "application starts up" with the exception TemplateNotFound: /.

The register function pasted here passes check50 (as long as url_for is imported from flask). url_for is not imported from flask in the current distribution code.

I know this doesn't answer the question, it only raises more questions. It could mean you are using the wrong distro code. Or it could indicate you have made changes to application.py (besides those already indicated here) that are affecting the outcome of check50. The current version of the spec is found here.

You must log in to answer this question.

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