[英]Python: Cannot call method from imported module
I have a simple function to log a user in. It first comfirms whether the users details are correct; 我有一个简单的功能可以登录用户。它首先确认用户详细信息是否正确;然后确认用户详细信息是否正确。
import user
@app.route("/login/", methods=['POST', 'GET'])
def login():
if request.method == 'GET':
return render_template('login.html')
else:
_email = request.form['email']
_password = request.form['password']
if user.loginValidate(_email, _password) == True:
session['username'] = user.getUserName(_email)
session['loggedin'] = True
return redirect(url_for('home'))
else:
flash('Email or password incorrect!')
return render_template('login.html')
Now for some reason when I try to call loginValidate
I get an error that 'function' object has no attribute loginValidate
. 现在由于某种原因,当我尝试调用
loginValidate
,出现一个错误,提示'function' object has no attribute loginValidate
。
The module does have loginValidate
which returns either True
or False
, so I don't see what the issue is. 该模块确实具有
loginValidate
,它返回True
或False
,所以我看不出问题是什么。
loginValidate
(within user
module): loginValidate
(在user
模块内):
def loginValidate(this_email, this_password):
db = sqlite3.connect('data')
cursor = db.cursor()
cursor.execute("SELECT password FROM users WHERE email = ?", (this_email,))
row = cursor.fetchone()
hash = row[0]
db.close()
return hash == bcrypt.hashpw(this_password, hash)
Any help is appreciated! 任何帮助表示赞赏!
Try: 尝试:
from user import loginValidate
And: 和:
if loginValidate(_email, _password) == True:
While I can't exactly point to where this arises, the error itself seems a clear enough hint. 尽管我无法确切指出发生的地方,但错误本身似乎足够清晰。 Python thinks that "user" is a function, not a module.
Python认为“用户”是一个函数,而不是一个模块。 Maybe there's a "user" function defined somewhere else, and python actually imports that
也许在其他地方定义了“用户”功能,而python实际上将其导入
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.