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