UserCreationForm is for creating . Better to create a new ModelForm than use this.
class UserUpdateForm(forms.ModelForm):
Or if you want to subclass UserCreationForm , which I do not recommend. You can do it:
class UserForm(UserCreationForm): password1 = forms.CharField(label=_("Password"), required=False widget=forms.PasswordInput) password2 = forms.CharField(label=_("Password confirmation"), widget=forms.PasswordInput, required=False) class Meta: model = User fields = ('first_name', 'last_name', 'username', 'email') def save(self, commit=True): user = super(UserUpdateForm, self).save(commit=False) password = self.cleaned_data["password"] if password: user.set_password(password) if commit: user.save() return user
I recommend you use a simple
class UserUpdateForm(forms.ModelForm): class Meta: model = User
There is another special form that you can use to change passwords, which is django.contrib.auth.forms.SetPasswordForm , since changing a password is another process of updating user information
Anass source share