django customize reset password form

南楼画角 提交于 2019-11-29 11:47:24

You want to customise the password_reset view. By default, it uses the PasswordResetForm, which you can customize.

# in e.g. myapp/forms.py
from django.contrib.auth.forms import PasswordResetForm

class CaptchaPasswordResetForm(PasswordResetForm):
    captcha = ReCaptchaField()
    ...

Then in your urls.py, import your form, and use the password_reset_form argument to specify the form.

from django.contrib.auth import views as auth_views
from myapp.forms import CaptchaPasswordResetForm

urlpatterns = [
    ...
    url(
        '^password_reset/',
        auth_views.password_reset,
        {'password_reset_form': CaptchaPasswordResetForm},
    )
]

For more information about including password reset views in your urls, see the docs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!