Session query
- From:
- Lix Xu
- Date:
- 2011-05-24 @ 09:58
Hi,
It seems that session can not store a class object, is it true?
I always get the error, "TypeError: 'NoneType' object is not callable".
Or, if it can store the object, but can not call its methods.
Below are some items that I can't understand.
cart_id is from id(cart)
Why cart_id is the same, the cart object is different, and if I call its
method, it will raise "TypeError: 'NoneType' object is not callable".
<Session {'lang': u'en', '_csrf_token':
'fc91c65a-4385-4a76-8d55-33decc6722c6', 'user_id':
ObjectId('4dca070070fa88512e000000'), 'cart_id': 139756625776528, 'cart':
<automation.models.cart.Cart object at 0x7f1ba00a3590>}*>
127.0.0.1 - - [24/May/2011 17:24:24] "GET /materials/ HTTP/1.1" 200 -
in find_cart <automation.models.cart.Cart object at 0x7f1ba009ee10>
127.0.0.1 - - [24/May/2011 17:24:37] "GET
/trades/add-to-cart/4dda2ea170fa88496d000000/ HTTP/1.1" 302 -
<Session {'lang': u'en', '_csrf_token':
'fc91c65a-4385-4a76-8d55-33decc6722c6', 'user_id':
ObjectId('4dca070070fa88512e000000'), 'cart_id': 139756625776528, 'cart':
<automation.models.cart.Cart object at 0x7f1ba0180bd0>}*>
Re: [flask] Session query
- From:
- Ron DuPlain
- Date:
- 2011-05-24 @ 17:33
Hi,
On Tue, May 24, 2011 at 5:58 AM, Lix Xu <xuzenglin@gmail.com> wrote:
> It seems that session can not store a class object, is it true?
flask.session is using Werkzeug's SecureCookie. Since you're storing
values in a browser cookie, you'll have to serialize your class. See:
http://werkzeug.pocoo.org/docs/contrib/securecookie/
-Ron
Re: [flask] Session query
- From:
- Wilson Xu
- Date:
- 2011-05-24 @ 17:15
You need to serialize objects before saving to session, and deserialize them
after taking out.
--
Think and code - imwilsonxu.net