Home > Software engineering >  Unsafe redirect to URL with protocol django rest framework
Unsafe redirect to URL with protocol django rest framework

Time:11-05

When the user completes the registration process, I want to redirect her to the login page, where I get the following error.

Unsafe redirect to URL with protocol 'accounts'

What method should I use to solve this error?

class RegisterUser(APIView):
    serializer_class = RegisterSerializer
    def post(self, request):
        serializer = self.serializer_class(data=request.POST)
        serializer.is_valid(raise_exception=True)
        serializer.save()
        return HttpResponseRedirect('accounts:login')

CodePudding user response:

Simply you can try this way:

Change this:

return HttpResponseRedirect('accounts:login')

To:

return HttpResponseRedirec('/accounts/login/')

Try and see if it solves the error

CodePudding user response:

It should be either:

return redirect('accounts:login')

or:

return HttpResponseRedirect(reverse('accounts:login'))
  • Related