名称错误: 未定义全局名称'hashed_pwd'



我是新来的python和烧瓶。我进行登录和注册页面,一切正常。存储在数据库中,但是当我尝试登录时,我会出现一个错误" nameRorr:blobal name'hashed_pwd'未定义"请提供解决方案。

@app.route('/signUp', methods=['POST','GET'])
def signUp():   
        _name = request.form['user_name']        #database connectivity
        _password = request.form['user_password']
        _pname = request.form['patient_name']
        _email = request.form['user_email']
        _cont = request.form['user_contact']
        _add = request.form['user_address']
        if _name and _password and _pname and _email and _cont and _add:
            conn = mysql.connect()
            cursor = conn.cursor()
            hashed_pwd=generate_password_hash(_password)    #password generated
            query_string = """INSERT INTO tbl_puser (user_name,user_password,patient_name,user_email,user_contact,user_address) VALUES('%s','%s','%s','%s','%s','%s');"""%(_name,hashed_pwd,_pname,_email,_cont,_add)
            print query_string
            cursor.execute(query_string)
            conn.commit()
            cursor.close()
            conn.close()
            flash('You were successfully registered')
            return render_template('select.html')

@app.route('/Login',methods=['POST','GET'])
def login():
    user_name=request.form['uname']
    user_password=request.form['psw']
    # NameError: global name 'hashed_pwd' is not defined error 
    check_password_hash(hashed_pwd,user_password) 
        if user_name and user_password:
            conn = mysql.connect()
            cursor = conn.cursor()
            cursor.execute("SELECT * from tbl_puser where user_name='" + user_name + "' and user_password='"+ user_password +"'")
            print "SELECT * from tbl_puser where user_name='" + user_name + "' and user_password='"+ user_password +"';"
            data = cursor.fetchall()
            print data
            if len(data) != 0:
                return render_template("select.html")
            else:
                return redirect(url_for('index'))
if __name__ == '__main__':
    app.run()

您简单地忘记了它

user_password = request.form.get('psw', '')
# Add next line
hashed_pwd = generate_password_hash(user_password)
check_password_hash(hashed_pwd,user_password)

更好地使用request.formget获取项目的值。

相关内容

  • 没有找到相关文章

最新更新