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
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:
Theis_authenticated
,is_active
, andis_anonymous
members of the user class are now properties, not methods. Applications should update their user classes accordingly.
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
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