I am trying to add custom class to django password change form by extending to my custom form. But keep getting the error:

TypeError: password_change() got an unexpected keyword argument 'form'

Custom form that i use for the change password: Note: I tried extending to SetPasswordForm as well since PasswordChangeForm is a subclass of it but no dice. userapp.forms:

from django.contrib.auth.forms import SetPasswordForm, PasswordChangeForm

attrs_dict = {'class':'required form-control'}

    class CustomChangePasswordForm(PasswordChangeForm):
        old_password = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
        new_password1 = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))
        new_password2 = forms.CharField(widget=forms.TextInput(attrs=attrs_dict))

added this line in urls.py:

url(r'^accounts/password/change/$', 'django.contrib.auth.views.password_change', {'form': CustomChangePasswordForm}),
url(r'^accounts/register/$', register, { 'backend': 'registration.backends.default.DefaultBackend','form_class':UserRegistrationFormz}, name='registration_register'),
url(r'^accounts/vendor-register/$', register, { 'backend': 'registration.backends.default.DefaultBackend','form_class':VendorRegistrationForm}, name='vendor_register'),
url(r'^accounts/', include(regUrls)),
有帮助吗?

解决方案

Change

{'form': CustomChangePasswordForm}

to

{'password_change_form': AdminPasswordChangeForm}

Reference: Source code

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top