您的位置:首页 > 移动开发 > Objective-C

Flask--AttributeError 'bool' object has no attribute '__call__'

2016-03-05 13:13 501 查看
2016年3月1日

在学习Flask-Login模块时,出现了报错
builtins.AttributeError AttributeError: 'bool' object has no attribute '__call__'


参考资料When I run app.py, why am I getting: builtins.AttributeError AttributeError: ‘bool’ object has no attribute ‘call

Kenneth Love:Posting this here so people can see it, this comes from a change in how UserMixin works in flask-login. I’d tell you to install a specific version of flask-login but…they removed those releases from PyPI.

So…instead of {{ current_user.is_authenticated() }}, you need to use {{ current_user.is_authenticated }}. Just don’t include the parentheses. Yeah, it’s an annoying change but, honestly, I think it’s probably better code design.

原因:flask-login 模块里的
UserMixin
类由于版本更新后,修改了它的
is_authenticated()
方法,在之前的版本中是使用
UserMixin.is_authenticated()
根据用户已经登录返回
True
,未登录返回
False
,而现在改成使用
UserMixin.is_authenticated
了。上文中的Kenneth Love表示虽然这是个烦人的改变,但他认为这是一种更好的代码设计。

解决办法:去掉
is_authenticated()
中的括号。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: