开发者

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'] = []
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜