jeudi 14 décembre 2017

How to i prevent my code from producing a syntax error on my else statement

Hello this is my first post, I'm fairly new to coding Python (6 months). I've been working on this flask app and keep running into a Syntax error with my else statement on the last line. I've seen answers say it could be an indentation issue, but I've tried that solution with no success. I'm sure there's something blindingly obvious about the issue, but after starting and stopping several times i can't seem to spot it. PLEASE help

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

if request.method == "POST":
    if not request.form.get("username") or not request.form.get("password"):
        return apology("Provide Username AND Password Silly!")
    elif not request.form.get("password2"):
        return apology("Must Confrim Password")
    elif request.form.get("password2") != request.form.get("password"):
        return apology("Passwords Didn't Match")

    hashi, username = pwd_context.encrypt(request.form.get("password")), request.form.get("username")

    CheckUsername = db.execute("INSERT INTO \
    users (username, hashi) VALUES(:username :hashi)", \
    username=username, hashi=hashi)
    if not CheckUsername:
        return apology("username already exist")

    CheckNow = db.execute("SELECT * FROM users WHERE username = :username", username=username)
    if not CheckNow:
        return apology("Something Bad Happened, Let Us Know")

    session["user_id"] = CheckNow[0]["id"]
    return redirect(url_for("history")
else:
    return render_template("register.html")

Aucun commentaire:

Enregistrer un commentaire