﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
22591	Changing of HTTP status code in form_invalid()	kevmo314@…	nobody	"Would it be possible to permit the changing of status codes on form_invalid? We had a form where we wanted to return a 400 status code when a validation error occurs, but by default Django spits out a 200 error code. In other words, following the example at [https://docs.djangoproject.com/en/dev/topics/class-based-views/generic-editing/#ajax-example], we'd like to return a 400 on a non-ajax request as well.

Here's the change I'd like to propose. On line 78 of django/views/generic/edit.py:

{{{
    def form_invalid(self, form, **kwargs):
        """"""
        If the form is invalid, re-render the context data with the
        data-filled form and errors.
        """"""
        return self.render_to_response(self.get_context_data(form=form), **kwargs)
}}}

This would permit doing something like this:

{{{
response = super(AjaxableResponseMixin, self).form_invalid(form, status=400)
}}}

Alternatively, a failure status code property may be more intuitive to developers, but I think the above permits a bit more flexibility in terms of modifying other attributes of the response as well."	New feature	closed	Forms	dev	Normal	wontfix	forms	Adam Wróbel	Unreviewed	1	0	0	0	1	0
