[Django]-How to redirect to the same page after an action in django

4👍

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

3👍

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)
👤Lag11

0👍

Send the address where you are calling from in kwargs and redirect to that.

0👍

HttpRequest

from django.http import HttpResponseRedirect


return HttpResponseRedirect(request.path_info)

0👍

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

Leave a comment