Search code examples
djangohttp-redirecthttp-status-code-403http-error

Redirection + 403 error


I am searching for a way to have something like that :

return HttpResponseForbiddenRedirect(reverse("view_name"))

an HttpResponse which redirect to a view (with its name) but still throw a 403 error

I tried to do something like that :

class HttpResponseForbiddenRedirect(HttpResponse):
    def __init__(self, redirect_to):
        super(HttpResponseForbiddenRedirect, self).__init__()
        self['Location'] = iri_to_uri(redirect_to)
        self.status_code = 403

But it didn't work. For some reason I don't understand, I don't get any content


Solution

  • I found a solution to this :

    from app_name.views import my_view
    
    ....
        retour = my_views(request)
        return HttpResponseForbidden(retour)
    

    It is in fact quite simple

    And so I get the 403 error + the page I wanna load