'Return the user-originating redirect URL if it\'s safe.'

def get_redirect_url(self):

    redirect_to = self.request.POST.get(self.redirect_field_name, self.request.GET.get(self.redirect_field_name, ''))
    url_is_safe = is_safe_url(url=redirect_to, allowed_hosts=self.get_success_url_allowed_hosts(), require_https=self.request.is_secure())
    return (redirect_to if url_is_safe else '')
