clean() is called after the individual fields have been validated and so it would not solve, for example, extra whitespace at the end of a password. I like to override full_clean() instead.
def full_clean(self): stripped_data = {} for k, v in self.data.items(): stripped_data[k] = v.strip() self.data = stripped_data super(LoginForm, self).full_clean()
Comment
clean() is called after the individual fields have been validated and so it would not solve, for example, extra whitespace at the end of a password. I like to override full_clean() instead.
def full_clean(self):
stripped_data = {}
for k, v in self.data.items():
stripped_data[k] = v.strip()
self.data = stripped_data
super(LoginForm, self).full_clean()