0
def register():
    session.clear()
    if request.method == "POST":
        if not request.form.get("username"):
        return apology("Missing Username!")
        elif not request.form.get("password"):
        return apology("Missing Password!")

        if not request.form.get("password") == request.form.get("Confirm password"):
        return apology("Password and Password Confirmation are not consistent!")

        hash = pwd_context.hash("password")
        result = db.execute("INSERT INTO users(username, hash) VALUES(:username, :hash)",
                        username=request.form.get("username"), hash=hash)
        if not result:
        return apology("Username exists already")

        session["user_id"] = rows[0]["id"]
    return render_template("register.html")

I got this name error from trying to register. Can someone help me please i have tried figuring it out and all i got was that pwd_context.encrypt has to change to pwd_context.hash and it still couldnt work...

hash = pwd_context.hash("password") result = db.execute("INSERT INTO users(username, hash) VALUES(:username, :hash)", username=request.form.get("username"), hash=hash) if not result: return apology("Username exists already")

NameError: name 'pwd_context' is not defined

0

In my application.py, pwd_context is defined by

from passlib.apps import custom_app_context as pwd_context

at the top.

BTW, you hash the word "password", not the password.

And I hope all of your if and else have the right indentation and you just messed it up when posting the code (you use that {} button or Ctrl+K in the post editor?)

| improve this answer | |
  • Thank you. Are you supposed to add that import on your own? Or was it in application.py in the first place? The indentations were messed up when posting the code lol. Sorry still new to posting codes online – Shane Nov 4 '17 at 3:23
  • I rarely use imports with as, so either it was there from the beginning, or I copy&pasted it from somewhere else. – Blauelf Nov 4 '17 at 10:37
  • Included in the specification: "Instead of pwd_context.encrypt, which Zamyla mentions, be sure to use generate_password_hash instead." Import for that included at top of current application.py – easybeinggreen Mar 2 '18 at 1:20

You must log in to answer this question.

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