每当我试图订购一些东西,我不断得到这个错误。
这是我的views.py:
if not request.user.is_authenticated:
session = request.session
cart = session.get(settings.CART_SESSION_ID)
if cart:
del session[settings.CART_SESSION_ID]
else:
customer = request.user.customer
order, created = Order.objects.get_or_create(
customer=customer, complete=False)
order_products = OrderProduct.objects.filter(order=order)
if order_products:
order_product = order_products[0]
else:
order_product = OrderProduct.objects.create(order=order)
order.save()
messages.success(request, 'Заказ успешно оформлен. Проверьте свою электронную почту!!!')
session = request.session
del session[settings.CART_SESSION_ID]
return redirect('product_list')
请问有谁能帮我修一下吗?
1条答案
按热度按时间3htmauhk1#
您的会话中不存在该密钥,因此请在删除之前检查它是否存在