英文:
There is error when trying to make order in django
问题
当我尝试订购东西时,一直出现这个错误:
这是我的views.py文件:
if not request.user.is_authenticated:
session = request.session
cart = session.get(settings.CART_SESSION_ID)
del session['cart']
else:
customer = request.user.customer
order, created = Order.objects.get_or_create(
customer=customer, complete=False)
order_product, created = OrderProduct.objects.get_or_create(
order=order, )
order.save()
messages.success(request, 'Заказ успешно оформлен. Проверьте свою электронную почту!!!')
return redirect('product_list')
请问有谁能帮助我修复这个错误?
英文:
When I try to order something, I keep getting this error:
Here is my views.py
if not request.user.is_authenticated:
session = request.session
cart = session.get(settings.CART_SESSION_ID)
del session['cart']
else:
customer = request.user.customer
order, created = Order.objects.get_or_create(
customer=customer, complete=False)
order_product, created = OrderProduct.objects.get_or_create(
order=order, )
order.save()
messages.success(request, 'Заказ успешно оформлен. Проверьте свою электронную почту!!!')
return redirect('product_list')
Please can anyone help me to fix this error?
答案1
得分: 0
以下是翻译好的部分:
if not request.user.is_authenticated:
session = request.session
cart = session.get(settings.CART_SESSION_ID)
if cart is not None:
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
cart = session.get(settings.CART_SESSION_ID)
if cart is not None:
# Remove cart items from the session
del session[settings.CART_SESSION_ID]
session.modified = True
return redirect('product_list')
注意:上述代码中包含了一个俄语文本 'Заказ успешно оформлен. Проверьте свою электронную почту!!!'
,没有提供翻译,保留原文。
英文:
if not request.user.is_authenticated:
session = request.session
cart = session.get(settings.CART_SESSION_ID)
if cart is not None:
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
cart = session.get(settings.CART_SESSION_ID)
if cart is not None:
# Remove cart items from the session
del session[settings.CART_SESSION_ID]
session.modified = True
return redirect('product_list')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论