how to redirect in django rest framework

  1. Within your views.py file, import the RedirectView from django.views.generic.base module:
from django.views.generic import RedirectView
  1. Create a RedirectView subclass and define the pattern with the URL you want to redirect to, using the pattern_name attribute:
class MyRedirectView(RedirectView):
    pattern_name = 'target_url_name'
  1. Add the URL pattern to the urls.py file, specifying the path and the associated RedirectView subclass:
from django.urls import path
from .views import MyRedirectView

urlpatterns = [
    path('old-url/', MyRedirectView.as_view(), name='old_url_name'),
]