pythondjangodjango-forms

Clearing Django form fields on form validation error?


I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.

I've tried several methods for removing form.data, but I keep getting a This QueryDict instance is immutable exception message.

Is there a proper way to clear individual form fields or the entire form data set from clean()?


Solution

  • If you need extra validation using more than one field from a form, override the .clean() method. But if it's just for one field, you can create a clean_<field_name>() method.

    See here.