diff options
| author | Berker Peksag <berker.peksag@gmail.com> | 2016-08-24 20:20:12 +0300 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-08-24 13:20:12 -0400 |
| commit | 3c18f8a3d2f61669493f9ff2015ddc027eada3d6 (patch) | |
| tree | 0404984ebc4f2a04dcae05eb1c65afa6f186b6da /django | |
| parent | 9aaeec337e217109208672d8fe47eeb49ca492b5 (diff) | |
Fixed #27111 -- Fixed KeyError if USERNAME_FIELD isn't in UserCreationForm.fields.
Diffstat (limited to 'django')
| -rw-r--r-- | django/contrib/auth/forms.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py index 4246e09648..fe65bf3a6e 100644 --- a/django/contrib/auth/forms.py +++ b/django/contrib/auth/forms.py @@ -94,7 +94,8 @@ class UserCreationForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(UserCreationForm, self).__init__(*args, **kwargs) - self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({'autofocus': ''}) + if self._meta.model.USERNAME_FIELD in self.fields: + self.fields[self._meta.model.USERNAME_FIELD].widget.attrs.update({'autofocus': ''}) def clean_password2(self): password1 = self.cleaned_data.get("password1") |
