我正在尝试通过扩展到我的自定义表单将自定义类添加到django密码更改表单。但不断收到错误:
TypeError: password_change() got an unexpected keyword argument 'form'
我用于更改密码的自定义表单: 注意:我尝试扩展到SetPasswordForm,因为PasswordChangeForm是它的子类但没有骰子。 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))
在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)),
答案 0 :(得分:1)
更改
{'form': CustomChangePasswordForm}
到
{'password_change_form': AdminPasswordChangeForm}
参考:Source code