I am a beginner in django (django 1.7 python 2.7).
I am trying to add no captcha recaptcha onto my django reset password form.
I am trying to use this recapt
You want to customise the PasswordReset 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 form_class
to specify the form.
from django.contrib.auth import views as auth_views
from django.urls import path
from web.forms import CaptchaPasswordResetForm
urlpatterns = [
path("accounts/password_reset/", auth_views.PasswordResetView.as_view(form_class=CaptchaPasswordResetForm)),
]
For Django < 1.11, you need to customise the URL pattern for the password_reset
view, and set password_reset_form
to
from django.contrib.auth import views as auth_views
from myapp.forms import CaptchaPasswordResetForm
urlpatterns = [
...
url(
r'^password_reset/',
auth_views.password_reset,
{'password_reset_form': CaptchaPasswordResetForm},
)
]
For more information about including password reset views in your urls, see the docs.