Answer the question
In order to leave comments, you need to log in
How to update the dictionary?
There is the following representation:
def shopping_cart_add(request):
selected_item = request.GET.get('selected_item')
if request.session.get('cart', False):
request.session['cart'].extend(selected_item)
else:
request.session['cart'] = []
request.session['cart'].extend(selected_item)
Answer the question
In order to leave comments, you need to log in
request.session['cart'].extend(selected_item)
This code does not add anything to the dictionary, this code adds the elements from 'selected_item' to the dictionary element with the key 'cart'.
Explain what exactly you want? Still, add a new element to the dictionary , or add a value to the element that is in the dictionary ?
What is the element with the 'cart' key (as I understand it, this is a list)? What is the 'selected_item' object (also a list?)?
if request.session.get('cart', False):
if 'cart' in request.session:
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question