I'm also getting an Index Error, "list index out of range" for the "request.session['cart'][1] += 1" line. I can't figure out what's wrong.
On Feb 9, 3:02 am, lnysrogh <lordnysr...@gmail.com> wrote: > Thank you so much. That helped a lot. Such a simple mistake. > > I've got some other questions now. My "add to cart" code: > > def add(request, product_id): > added = (Product.objects.get(id=product_id), 1) # '1' is quantity > request.session.set_test_cookie() > if request.session.test_cookie_worked(): > request.session.delete_test_cookie() > if 'cart' in request.session: > if added in request.session['cart']: > request.session['cart'][1] += 1 > else: > request.session['cart'].append(added) > else: > request.session['cart'] = [] > request.session['cart'].append(added) > return HttpResponseRedirect('/cart/') > else: > return HttpResponse('You need to enable cookies') > > The code worked until I tried to check if the product is already > stored in the cart and to add 1 to the quantity instead of storing it > again. I'm getting this error: "can only concatenate tuple (not "int") > to tuple". What am I doing wrong? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---