#24465: Failed logins are recorded as HTTP 200 instead of HTTP 403
-----------------------------------+--------------------------------------
Reporter: Mark Litwintschik | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.7
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Comment (by cpbotha):
Just in case anyone else also spends hours trying to figure out how to get
the LoginView to return a response with HTTP status 401 instead of 200:
The call hierarchy is: `LoginView.form_invalid() ->
TemplateResponseMixin.render_to_response() -> TemplateResponse ->
SimpleTemplateResponse -> HttpResponse -> HttpResponseBase which has the
default status code 200`
To change to 401, which still just re-renders the form, but now nicely
logs the 401, do something like this:
{{{#!python
from django.contrib.auth.views import LoginView
class LoginView401(LoginView):
def form_invalid(self, form):
return self.render_to_response(self.get_context_data(form=form),
status=401)
}}}
... and then use `LoginView401` in your `urls.py`
Thanks to rudi@zatech for putting me on the right path.
--
Ticket URL: <https://code.djangoproject.com/ticket/24465#comment:6>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.5c168e9ca97f73718d1927771dd89575%40djangoproject.com.