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:)
CodePudding user response:
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.