Flask view raises TypeError: #39;bool#39; object is not callable(Flask 视图引发 TypeError:bool 对象不可调用)
问题描述
I am trying to debug a view in my Flask app that is return a 500 status with the error TypeError: 'bool' object is not callable
in the traceback. The view calls login_user
from Flask-Login then returns True
to indicate that the login was successful.
I have debugged until app_iter = app(environ, start_response)
and the app
is now a boolean with the value True
rather than the Flask app object.
Traceback (most recent call last):
File "D:Python27libsite-packagesflaskapp.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "D:Python27libsite-packagesflaskapp.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "D:Python27libsite-packagesflaskapp.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "D:Python27libsite-packagesflaskapp.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "D:Python27libsite-packagesflaskapp.py", line 1478, in full_dispatch_request
response = self.make_response(rv)
File "D:Python27libsite-packagesflaskapp.py", line 1577, in make_response
rv = self.response_class.force_type(rv, request.environ)
File "D:Python27libsite-packageswerkzeugwrappers.py", line 824, in force_type
response = BaseResponse(*_run_wsgi_app(response, environ))
File "D:Python27libsite-packageswerkzeugwrappers.py", line 57, in _run_wsgi_app
return _run_wsgi_app(*args)
File "D:Python27libsite-packageswerkzeug est.py", line 854, in run_wsgi_app
app_iter = app(environ, start_response)
TypeError: 'bool' object is not callable
@app.route('/login', methods=['POST'])
def login():
username = request.form['username']
user = User.query.filter_by(username=username).first()
if user:
login_user(user)
return True
return False
In Flask, a view must return one of the following:
- a string
- a
Response
object (or subclass) - a tuple of
(string, status, headers)
or(string, status)
- a valid WSGI application
Flask tests for the first 3 options, and if they don't fit, assumes it is the fourth. You returned True somewhere, and it is being treated as a WSGI application instead.
See About Responses in the documentation.
这篇关于Flask 视图引发 TypeError:'bool' 对象不可调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Flask 视图引发 TypeError:'bool' 对象不可调用


基础教程推荐
- 在 Python 中将货币解析为数字 2022-01-01
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01