Created
March 26, 2014 11:57
-
-
Save oprypin/f2e1cd5f74d4809fbbc0 to your computer and use it in GitHub Desktop.
Flask current_user function to load the user only when needed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def current_user(): | |
try: | |
return g.current_user | |
except RuntimeError: | |
return None | |
except AttributeError: | |
try: | |
g.current_user = db.query(User).get(session['user_id']) | |
except KeyError: | |
g.current_user = None | |
return g.current_user |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment