I tried to use is_authenticated()
in a view, but got the error `TypeError: 'bool' object is not callable. Why am I getting this error and how do I fix it?
@auth.before_app_request def before_request(): if current_user.is_authenticated() \ and not current_user.confirmed \ and request.endpoint[:5] != 'auth.' \ and request.endpoint != 'static': return redirect(url_for('auth.unconfirmed'))
The Python "TypeError: 'bool' object is not callable" occurs when we try to call a boolean value ( True or False ) as a function. To solve the error, correct the assignment and resolve any clashes between function and variable names.
Bool type objects do not respond to a function call because they are not functions. If you try to call a Bool type object if it were a function, the Python interpreter will raise the TypeError: 'bool' object is not callable.
"object is not callable" error occurs when you are trying to behave an object like it is a method or function.
in this case:
current_user.is_authenticated()
you are behaveing current_user.is_authenticated as a method but its not a method .
you have to use it in this way :
current_user.is_authenticated
you use "( )" after methods or functions, not objects.
In some cases a class might implement __call__
function which you can call an object too, then it will be callable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With