permanent redirect django

from django.shortcuts import redirect

def my_view(request):
    # some code here
    return redirect('/some/url/', permanent=True)

Here is what the above code is Doing:
1. It’s checking if the request is an AJAX request.
2. If it is, it’s returning a redirect response with the status code 301.
3. If it’s not, it’s returning a redirect response with the status code 302.

The permanent argument is set to True by default, so you only need to specify it if you want to return a 302 redirect.

Note that this only works if you’re using Django’s built-in redirect() function. If you’re using HttpResponseRedirect, you’ll need to set the status code manually:

from django.http import HttpResponseRedirect

def my_view(request):
# some code here
return HttpResponseRedirect(‘/some/url/’, status=301)