Alex Rivera | Logout

How do I return a 401 Unauthorized in Django?

Asked 2010-12-05T01:15:28.083
73

Instead of doing this:

res = HttpResponse("Unauthorized")
res.status_code = 401
return res

Is there a way to do it without typing it every time?

Edit
Report

1 Answer

9
class HttpResponseUnauthorized(HttpResponse):
    def __init__(self):
        self.status_code = 401

...
return HttpResponseUnauthorized()
answered 2010-12-05T01:26:35.197

Your Answer