我的Django应用程序中有一个添加到购物车按钮。当我点击添加到购物车按钮时,我收到ERR_EMPTY_RESPONSE错误,但产品已添加到购物车。当我点击购物车链接放置在我的页面右上方时,我能够看到我的购物车,但当我点击添加到购物车按钮时,我看不到它。它什么都没有。什么可能导致这个问题?任何帮助都会得到满足。
def add_to_cart(request):
postdata = request.POST.copy()
# get product slug from post data, return blank if empty
product_slug = postdata.get('product_slug','')
# get quantity added, return 1 if empty
quantity = postdata.get('quantity',1)
# fetch the product or return a missing page error
p = get_object_or_404(Product, slug=product_slug) #django shortcuts helper method
#get products in cart
cart_products = get_cart_items(request)
product_in_cart = False
# check to see if item is already in cart
for cart_item in cart_products:
if cart_item.product.id == p.id:
# update the quantity if found
cart_item.augment_quantity(quantity)
product_in_cart = True
if not product_in_cart:
# create and save a new cart item
ci = CartItem()
ci.product = p
ci.quantity = quantity
ci.cart_id = _cart_id(request)
ci.save()
答案 0 :(得分:0)
你应该回复一个回复。例如:
导入render_to_response
:
from django.shortcuts import render_to_response
并在您的视图中使用它:
return render_to_response( 'your_template')
另请参阅this。