正在尝试自定义Django SetPasswordForm

2024-10-06 12:35:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图重写SetPasswordForm以添加占位符和类,但似乎无法正常工作。我设法做到了登录页和密码重置页,但在这里我卡住了。在

class MySetPasswordForm(SetPasswordForm): new_password1 = forms.CharField( label=_("New password"), widget=forms.PasswordInput(attrs={'placeholder': 'New Password', 'class': 'password1'}), strip=False, help_text=password_validation.password_validators_help_text_html(), ) new_password2 = forms.CharField( label=_("New password confirmation"), strip=False, widget=forms.PasswordInput(attrs={'placeholder': 'Repeat Password', 'class': 'password2'}), ) ^{pr2}$

这个准确吗?在


Tags: newformspasswordwidgetattrslabelplaceholderclass
2条回答

Override or customize the django auth setPasswordFrom and PasswordResetForm, answer already give but without using path() in django url i.e django 1.11 I have done in below ways. Copy the setPasswordFrom form folder structure django.contrib.auth.forms import SetPasswordForm.

In urls.py

    from django.conf import settings
    from django.conf.urls import url
    from django.conf.urls.static import static
    from django.contrib.auth import views as auth_views
    from GetAdmin360.forms import (EmailValidationOnForgotPassword, CustomSetPasswordForm)

urlpatterns = [
url(r'^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', auth_views.PasswordResetConfirmView.as_view(form_class = CustomSetPasswordForm), {'template_name': 'registration/password_reset_confirm.html'}, name='password_reset_confirm'),
] + + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

In forms.py in which I have override the setPasswordFrom and PasswordResetForm

^{pr2}$

您在URL模式中使用了错误的路径。它应该是:

'reset/<uidb64>/<token>/'

相关问题 更多 >