Flask-User-starter-app icon indicating copy to clipboard operation
Flask-User-starter-app copied to clipboard

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

Open nealwright opened this issue 9 years ago • 10 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!

nealwright avatar Sep 11 '15 01:09 nealwright

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).

jamescarignan avatar Sep 13 '15 05:09 jamescarignan

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.

nealwright avatar Sep 13 '15 16:09 nealwright

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: https://github.com/lingthio/Flask-User/pull/91

jamescarignan avatar Sep 13 '15 17:09 jamescarignan

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!

AdamSun avatar Jan 20 '16 08:01 AdamSun

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

guinslym avatar Mar 01 '16 05:03 guinslym

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.

Max-AR avatar Mar 08 '16 07:03 Max-AR

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

Charlie37 avatar Apr 05 '16 13:04 Charlie37

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()"

battouly avatar Apr 20 '16 07:04 battouly

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

lv10 avatar Apr 22 '17 20:04 lv10

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()"

HiIcy avatar Jun 26 '17 14:06 HiIcy