[Answered ]-Django: Fields aren't loaded in the forms

1👍

Try it:

self.fields['password1'] = forms.CharField(label=_("Password"),
            widget=forms.PasswordInput, required = False)
self.fields['password2'] = forms.CharField(label=_("Password confirmation"),
            widget=forms.PasswordInput, required = False,
            help_text = _("Enter the same password as above, for verification."))

1👍

This is a common error: you have overwritten the signature of the form’s __init__ method, so that the first argument is current_user. So when in your POST block you instantiate the form with UserProfileForm(request.POST, instance=user_profile), the data dictionary is taken for the current_user parameter and the actual data parameter is empty. Because it’s empty, the form is not bound, so there are no errors.

The best way to override a form’s __init__ is to take any new parameters from args or kwargs:

def __init__(self, *args, **kwargs):
    current_user = kwargs.pop('current_user')
    super(UserProfileForm, self).__init__(*args, **kwargs)
    etc.

0👍

Should it not just be {‘form’:form, } in the view def.
Then in the template use {{ form.as_p }}

Leave a comment