2π
β
When you submit a password with fewer than 5 characters, it fails the min_length
validation so password
is not in your formβs cleaned_data
dictionary. When you try to access the missing key, you get a KeyError
.
Instead, you should try:
original_password = self.cleaned_data.get('password', '')
which will return ''
if the password is too short.
As an aside, a clean_myfieldname
method should only rely on one field. If you want to clean and validate fields that rely on each other, use the clean
method for this (see the django docs).
π€Alasdair
0π
When you access self.cleaned_data
, the form validates all of its fields, which would cause the password field to be validated against its min_length
argument.
π€Joseph Spiros
Source:stackexchange.com