I'm adding data into array but, it's end up with only the last item in the array. It seems to overwrite
request.session['list'] = []
if request.开发者_StackOverflow中文版method =='POST':
newrecord = request.POST['market']
tmp = request.session['list']
tmp.append(newrecord)
request.session['market_list'] = tmp
I turn out that previous data was overwrite by the new one
You are assigning an empty list to request.session['list']
in the first line of the code snippet you have given. Is this by design? In that case it is no surprise that tmp
always ends up with one element only.
change request.session['list'] = []
to
if not request.session.has_key('list'):
request.session['list'] = []
精彩评论