Reputation: 393
I have this function add_to_cart
once a product is added to cart it should redirect to the same.( since the the answers have not solved the issue ).
I have changed at least should redirect to product detail page requires to pass an argument either slug or product id any idea
def add_to_cart(request, **kwargs):
------------------------
------------------------
messages.info(request, "item added to cart")
return redirect(reverse('products:single_product',args=(request)))
url for product detail
url(r'^(?P<slug>.*)/$',single, name="single_product"),
Upvotes: 3
Views: 6227
Reputation: 1
Use "request.path" to get the current url as shown below:
# "views.py"
from django.shortcuts import redirect
def my_view(request):
return redirect(request.path) # Here
Or, use "request.path_info" to get the current url as shown below:
# "views.py"
from django.shortcuts import redirect
def my_view(request):
return redirect(request.path_info) # Here
Upvotes: 0
Reputation: 2046
You can do:
return HttpResponseRedirect(request.path_info)
You can also read about how Request/Response works in Django but also about the request.path_info
in the docs
Upvotes: 4
Reputation: 542
You can use request.path to find the current url of the request and then redirect.
from django.shortcuts import redirect
return redirect(request.path)
Upvotes: 3
Reputation: 131
from django.http import HttpResponseRedirect
return HttpResponseRedirect(request.path_info)
Upvotes: 0
Reputation: 578
Send the address where you are calling from in kwargs and redirect to that.
Upvotes: 0