I am writing an online store in Django. How do I redirect to the same page? This is needed to remove an item from the popup cart. The delete from cart function:
def cart_remove_retail(request, slug):
cart = Cart(request)
product = get_object_or_404(Product, slug=slug)
cart.remove(product)
return #???
when i try:
return HttpResponseRedirect(request.path_info)
I get round-robin query.
Thanks!
CodePudding user response:
To redirect to the same page in django view you can use :
return redirect('.')
CodePudding user response:
Assuming you want to redirect to the page where the request to cart_remove_detail is originating, you can use
return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
Alternatively add a next parameter to the request to cart_remove_detail.