Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: '_AppCtxGlobals' object has no attribute 'current_user' #185

Closed
wagnerdelima opened this issue Oct 4, 2016 · 4 comments
Closed
Labels

Comments

@wagnerdelima
Copy link

The code was working perfectly untill I reached chapter about API. Now, it points to this file and piece of code:

authentication.py

in line: if not g.current_user.is_anonymous and not g.current_user.confirmed:
error: AttributeError: '_AppCtxGlobals' object has no attribute 'current_user'

@miguelgrinberg
Copy link
Owner

Something must be missing on your version of the app. See below where g.current_user is set:

https://github.com/miguelgrinberg/flasky/blob/master/app/api_1_0/authentication.py#L22

@wagnerdelima
Copy link
Author

Not really. My code is just the same as yours. Actually I though that: As in the before_request method tha call will be made before every request, how would the g.current_user be defined if you call it in the very before_request method?

@miguelgrinberg
Copy link
Owner

The verify_password is called automatically by the login_required decorator that is attached to the before_request function. That runs first and sets g.current_user.

It would be useful if you can debug on your side to figure out why the verify_password function isn't setting g.current_user.

@ListenLove
Copy link

Thanks!
I also forgot to set g.current_user = user, the user is set as user=User.query.filter_by(email=email_or_token.lower()).first() before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants