How to access data when form.is_valid() is false

Greg picture Greg · Apr 9, 2009 · Viewed 40.3k times · Source

When I have a valid Django form, I can access the data with form.cleaned_data. But how do I get at the data a user entered when the form is not valid i.e., form.is_valid is false.

I'm trying to access forms within a form set, so form.data seems to just give me a mess.

Answer

Dmitry Risenberg picture Dmitry Risenberg · Sep 17, 2009

You can use

form.data['field_name']

This way you get the raw value assigned to the field.