storing objects in session

21 views
Skip to first unread message

imgrey

unread,
Apr 6, 2012, 3:11:14 PM4/6/12
to Django users
I'm trying to store temporary cart in session, but cart items
disappear after 3-4 page reloads.
This is simplified version of my code, that reproduces the issue:

"""
class C(object):
ITEMS = {}

def pprint(self):
return str(self.ITEMS)

class I(dict):
pass

def my_context_processor(request):
import random

result = {}

if request.session.get('TEMP', None) is None:
request.session['TEMP'] = C()
cart = request.session['TEMP']

if not cart.ITEMS:
i = I()
i.cart = cart
i["a"] = random.randint(1,10)
i["b"] = random.randint(1,10)
cart.ITEMS['blah'] = i
request.session['TEMP'] = cart
request.session.modified = True

result['test'] = cart

return result
"""


In template, after third of fourth reload I see {{ test }} updated,
when it shouldn't. Why ?

Shawn Milochik

unread,
Apr 6, 2012, 5:22:45 PM4/6/12
to django...@googlegroups.com

Try using pdb and/or logging statements to trace it.

You will almost certainly find your problem that way. If not, you'll be able to ask a more specific question that will be easier for others to answer.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages