1
我想通过扩展到我的自定义窗体来向django密码更改表单添加自定义类。但不断收到错误:我使用的更改密码TypeError:password_change()得到了一个意想不到的关键字参数'form'
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)),
完美!非常感谢 :) – shaytac