Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'bool' object is not callable g.user.is_authenticated() [duplicate]

I am trying to do this in my Flask application. But I am getting an error like this

TypeError: 'bool' object is not callable. 

Here is the corresponding code:

@app.before_request
def before_request():
    g.user = current_user
    if g.user.is_authenticated():
       g.search_form = None
like image 985
Dopant Prashant Avatar asked Oct 11 '15 06:10

Dopant Prashant


2 Answers

Try replace if g.user.is_authenticated(): to if g.user.is_authenticated: like this:

@app.before_request
def before_request():
    g.user = current_user
    if g.user.is_authenticated:
       g.search_form = None

From the document:

is_authenticated

Returns True if the user is authenticated, i.e. they have provided valid credentials. (Only authenticated users will fulfill the criteria of login_required.)

As the document said, is_authenticated is a boolean(True or False).

And however, it was a function in the past, but it has been changed to boolean at version 3.0:

BREAKING:
The is_authenticated, is_active, and is_anonymous
members of the user class are now properties, not methods. Applications should update their user classes accordingly.

like image 96
Remi Crystal Avatar answered Oct 11 '22 01:10

Remi Crystal


This is because is_authenticated is not a function but a mere boolean. Try the following instead:

@app.before_request
def before_request():
    g.user = current_user
    if g.user.is_authenticated:
       g.search_form = None
like image 36
Games Brainiac Avatar answered Oct 11 '22 01:10

Games Brainiac