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
x
16
16
1
def postCommande(request):
2
for key,value in request.session.cart.items:
3
data={
4
'products':[
5
{
6
'date':'23-09-22 00:00:00',
7
'nameclient': request.POST['name'],
8
'type':'typeproduct'
9
}
10
]
11
}
12
url='http://myapi/products/postCommande'
13
x=requests.post(url,json=data)
14
15
return render(request,'panier/succes.html')
16
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.