'SessionStore' object has no attribute 'cart' – Django

I generated a basket with 2 products, at the level of the basket page and also on this same page I added a form to insert the customer’s name. by clicking on the submit button which will send the request to a view for insert into the database. but I have an error (‘SessionStore’ object has no attribute ‘cart’)
I am using django-shopping-cart 0.1
and also I am using an API to post the products


def postCommande(request):
  for key,value in request.session.cart.items:
               'date':'23-09-22 00:00:00',
               'nameclient': request.POST['name'],

  return render(request,'panier/succes.html')

And the error is on this line (for key,value in request.session.cart.items:)

>Solution :

The session object is a dict-like object. Check Django documentation on How to use sessions.

I think we should change

for key,value in request.session.cart.items:


for key,value in request.session.get("cart", {}).items():

To get your code to work.

Leave a Reply