lingthio / Flask-User-starter-app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'bool' object has no attribute '__call__' when visiting localhost:5000

nealwright opened this issue · comments

I followed the installation instructions and all of the requirements install successfully. I'm using the newest version of virtualenvwrapper. When I visit localhost:5000 I get the following error:

File "[path_to_project]/app/templates/layout.html", line 29, in block "body" 
{% if current_user.is_authenticated() %}
AttributeError: 'bool' object has no attribute '__call__'

I'm somewhat new to flask and to Python, apologies if this is not a problem with the application itself, but I am stumped as to how to fix it. I googled a couple of solutions and haven't found anything that works. Thank you!

I encountered this issue as well, and spent far too long in determining that it's caused by Flask-Login. They changed current_user.is_authenticated() to be a property in 0.3.0, and thus making a method call here generates this error. This will need to be updated in Flask-User, I'm going to submit a pull request shortly. In the meantime, you can downgrade to Flask-Login==0.2.11 which won't have those changes in yet(but I have no idea if that will break anything else - I'm guessing not, but caveat emptor).

Thank you! Really appreciate it. Yeah, it would be great to get this fixed. In the meantime I'll downgrade Flask-Login.

Edit: I tried this and got the following error:

UndefinedError: 'flask_login.AnonymousUserMixin object' has no attribute 'user_auth'

I might just go through and change it manually for the moment. Looks like it's only two files, views.py and decorators.py that need changes I believe.

Truth be told, I didn't really look at the changelist for 0.3.0, I was hoping it was just that one issue. FYI I'm using my patched version, and was able to go through the whole user registration/login/logout flow, so I suspect that the fix won't be that far out. You can track its progress here: lingthio/Flask-User#91

commented

I met this problem.I am using flask-login for the version of 0.3.2. As jamescarignan said,I use "current_user.is_authenticated" instead of "current_user.is_authenticated()" and it seems works, has no idea if there is another problem.has this be fixed? thx!

as @AdamSun and @jamescarignan . I actually had to write 'current_user.is_authenticated" without the parenteses at the end

commented

I have the exact same problem as well. I am using;
Flask-User (0.6.8) Flask-Login (0.3.2) Flask (0.10.1) Python 3.4.3+
@AdamSun and @jamescarignan that solution seems to work for me at this stage.

Exact same problem here. Like @guinslym , I now use {% if (current_user.is_authenticated) %} and it seems to work.

I had the same issue and just removed the parentheses after authenticated.
You should use "current_user.is_authenticated" instead of "current_user.is_authenticated()"

commented

Same issue here, I get the same problem whether I use "current_user.is_authenticated" or "current_user.is_authenticated()".

commented

wonderful!! I got that issue as well,and I adopt the way you said, wipe off "()",Using "current_user.is_authenticated" instead of "current_user.is_authenticated()"