Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

'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

Views.py

def postCommande(request):
  for key,value in request.session.cart.items:
    data={
    'products':[
             {
               'date':'23-09-22 00:00:00',
               'nameclient': request.POST['name'],
               'type':'typeproduct'
             }
          ]
       }
     url='http://myapi/products/postCommande'
     x=requests.post(url,json=data)

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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:

to

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

To get your code to work.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading