flask报了个这样的错是为什么

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()
阅读 6.2k
4 个回答

异常提示里有说:

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

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

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

下面这段文字没准能帮到你
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的回答。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题