Skip to content
Advertisement

‘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

JavaScript

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

Advertisement

Answer

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.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement