python - flask报了个这样的错是为什么
高洛峰
高洛峰 2017-04-17 16:16:18
[Python讨论组]
AttributeError
AttributeError: 'bool' object has no attribute '__call__'

Traceback (most recent call last)
File "/var/www/Reptile/trainTicketsSpriderV2/flask/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/var/www/Reptile/trainTicketsSpriderV2/flask/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/var/www/Reptile/trainTicketsSpriderV2/flask/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
Display the sourcecode for this frameOpen an interactive python shell in this framereraise(exc_type, exc_value, tb)
File "/var/www/Reptile/trainTicketsSpriderV2/flask/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

全部回复(4)
怪我咯

异常提示里有说:

AttributeError
AttributeError: 'bool' object has no attribute '__call__'

布尔值 bool 对象没有一个叫作 __call__ 的属性。

检查一下哪里返回了一个 bool 值,然后你 call/调用 它了。

PHP中文网

下面这段文字没准能帮到你
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的版本问题,flask-login2.x是current_user.is_authenticated(),flask-login3.x是current_user.is_authenticated。避免这个问题最好的办法就是使用虚拟环境并在requirement中写明版本号。至于flask-login为什么要改,可以看@alvy的回答。

大家讲道理

flask login好多坑 再也不用了

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号