'How to retrieve session data with Flask?
I have flask+wtforms application. I can see in login() user object stored as
if user:
if user.verify_password(form.password.data):
flash('You have been logged in')
user.logins += 1
db.session.add(History(user.uid))
db.session.commit()
session['user'] = user
Now I wanted to retrieve the user
if 'user' in session:
User=session.get('user')
print User.nickname ###<< how to retrieve specific object member?
It fails with message like :
Instance <User at 0x8e5a64c> is not bound to a Session; attribute refresh operation cannot proceed
Solution 1:[1]
To see all that is in your session you can print(session). You should get a response like
<SecureCookieSession {'_flashes': [('info', 'Duplication is not allowed ')], 'el1-s': 'Physics', 'el1grade-s': 'B2', 'el2-s': 'E-Maths', 'el2grade-s': 'A1', 'english-s': 'A1', 'mathematics-s': 'A1', 'science-s': 'A1', 'social-s': None}>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nana Kweku Adumatta |
