# recaptcha impossible insert in form reset confirm

**URL:** <https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527>\
**Category:** Mystery Errors\
**Created:** [March 26, 2024, 9:30pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527 "2024-03-26T21:30:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![luigiamorfini1982](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luigiamorfini1982/32/8836_2.png) [@luigiamorfini1982](https://forum.djangoproject.com/u/luigiamorfini1982)\
**Post date:** [March 26, 2024, 9:30pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/1 "2024-03-26T21:30:41Z")

</div>

Hi, impossible imported captcha in form reset confirm …

my code urls.py:

```auto
    path('password_reset/', auth_views.PasswordResetView.as_view(form_class=forms.PasswordReset), name='password_reset'),
    path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    path('reset/confirm/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(form_class=forms.PasswordResetForm), name='password_reset_confirm'),
    path('reset/complete/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
    

```

My views.py:

```auto
from django.http.response import Http404
from django.views import generic
from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404, render
import braces.views
from . import forms
from . models import User

class RegisterView(generic.CreateView):
    form_class = forms.RegisterForm
    success_url = reverse_lazy('login')
    template_name = "registration/register.html"

class Profile(braces.views.LoginRequiredMixin, generic.DetailView):
    model = User
    def get_object(self):
        return get_object_or_404(User, username=self.kwargs['username'])

class ProfileUpdate(braces.views.LoginRequiredMixin, generic.UpdateView):
    model = User
    def get_success_url(self):
        return reverse_lazy("user_profile", kwargs={"username": self.request.user.username})
    def get_object(self):
        return get_object_or_404(User, username=self.request.user.username)

class ProfileUpdatePhoto(braces.views.LoginRequiredMixin, generic.UpdateView):
    model = User
    success_url = reverse_lazy('user_profile_update_photo')
    def get_success_url(self):
        return reverse_lazy("user_profile", kwargs={"username": self.request.user.username})
    def get_object(self):
        return get_object_or_404(User, username=self.request.user.username)

```

html:

```auto
{% extends "layout/normal.html" %}
{% load crispy_forms_tags %}
{% block SITE_TITLE %} Reset conferma password {% endblock %}
{% block PAGE_TITLE %} Reset conferma password {% endblock %}

{% block content %}

{% if validlink %}
<p>Inserisci e conferma la nuova Password</p>
<form method="POST" novalidate>
    {% csrf_token %}
    <div class="form-row">
        <div class="form-group mb-0">
            {{ form.new_password1|as_crispy_field }}
        </div>
        <div class="form-group mb-0">
            {{ form.new_password2|as_crispy_field }}
        </div>
        <div class="form-group mb-0">
            {{ form.captcha|as_crispy_field }}
        </div>        
        <input type="submit" class="btn btn-info" value="Cambia Password">
</form>
{% else %}
<h1>Errore.</h1>
<p>Il link seguito non è più valido!</p>
{% endif %}
{% endblock %}

```

 ![Screenshot 2024-03-26 222734](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/d/5/d5b0533d665cd4c78faa662e074199a0c42c175d.png)

How to fixed problem ? using plugin: [django-recaptcha · PyPI](https://pypi.org/project/django-recaptcha)

Thanks, good night.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 26, 2024, 9:50pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/2 "2024-03-26T21:50:08Z")

</div>

Please post the forms you are using. (`forms.PasswordReset` and `forms.PasswordResetForm`) Ensure that you have added the `captcha` field in those forms as described in the docs. (See [GitHub - django-recaptcha/django-recaptcha: Django reCAPTCHA form field/widget integration app.](https://github.com/django-recaptcha/django-recaptcha#fields))

---

<div class="post-metadata">

**Author:** ![luigiamorfini1982](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luigiamorfini1982/32/8836_2.png) [@luigiamorfini1982](https://forum.djangoproject.com/u/luigiamorfini1982)\
**Post date:** [March 27, 2024, 11:02am UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/3 "2024-03-27T11:02:11Z")

</div>

ok, forms.py:

```auto
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm, UserChangeForm
from django import forms
from django_recaptcha.fields import ReCaptchaField
from django import forms
from . models import User
from django.utils.translation import gettext_lazy as _
from .widgets import CustomDatePickerWidget

class RegisterForm(UserCreationForm):
    captcha = ReCaptchaField()
    class Meta:
        model = User
        fields = ('email', 'username', 'password1', 'password2')

class LoginForm(AuthenticationForm):
    username = forms.CharField(label='Email / Username')
    captcha = ReCaptchaField()

class PasswordChange(PasswordChangeForm):
    captcha = ReCaptchaField()

class PasswordReset(PasswordResetForm):
    captcha = ReCaptchaField()
    
class PasswordResetForm(SetPasswordForm):
    captcha = ReCaptchaField()

class ProfileUpdate(forms.ModelForm):
    GENDER = (
        ("Male", _('Male')),
        ("Female", _('Female')),
        ("n/a", _('n/a')),
    )
    first_name = forms.CharField(label=_('First name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your first name"}), required = False)
    last_name = forms.CharField(label=_('Last name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your last name"}), required = False)
    gender = forms.ChoiceField(label=_('Gender'), choices=GENDER, widget=forms.RadioSelect, required=False)
    birthday = forms.DateField(label=_('Birthday'), required = False, widget=CustomDatePickerWidget())
    city = forms.CharField(label=_('City'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    location = forms.CharField(label=_('Location'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    phone = forms.CharField(label=_('Phone number'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    info = forms.CharField(label=_('Information user'), widget=forms.Textarea(attrs={"style": "height:160px; width:100%;"}), required=False)
    class Meta:
        model =User
        fields = ['first_name', "last_name", 'gender', 'birthday', 'city', 'location', 'phone', 'info']

class ProfileUpdatePhoto(forms.ModelForm):
    photo = forms.ImageField(required = False)
    class Meta:
        model =User
        fields = ['photo']

```

1 ) Ok, in password reset form

 ![Screenshot 2024-03-27 115557](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/5/9/59015d07a00f32a0bf1c80f5bdf02c56f2422283.png)

1. Not working in form reset confirm form

 ![Screenshot 2024-03-27 115618](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/7/9/791a866f9069c826511ceabaa94d1d1112d396bf.png)

code error:

 ![Screenshot 2024-03-27 120021](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/a/4/a42426678023e227b98d83a6c036885c15b4f31b.png)

my html:

```auto
{% extends "layout/normal.html" %}
{% load crispy_forms_tags %}
{% block SITE_TITLE %} Reset conferma password {% endblock %}
{% block PAGE_TITLE %} Reset conferma password {% endblock %}

{% block content %}

{% if validlink %}
<p>Inserisci e conferma la nuova Password</p>
<form method="POST" novalidate>
    {% csrf_token %}
    <div class="form-row">
        <div class="form-group mb-0">
            {{ form.new_password1|as_crispy_field }}
        </div>
        <div class="form-group mb-0">
            {{ form.new_password2|as_crispy_field }}
        </div>
        <div class="form-group mb-0">
            {{ form.captcha|as_crispy_field }}
        </div>        
        <input type="submit" class="btn btn-info" value="Cambia Password">
</form>
{% else %}
<h1>Errore.</h1>
<p>Il link seguito non è più valido!</p>
{% endif %}
{% endblock %}

```

Ok thanks, How to fixed problem ?  
Good morning.

---

<div class="post-metadata">

**Author:** ![luigiamorfini1982](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luigiamorfini1982/32/8836_2.png) [@luigiamorfini1982](https://forum.djangoproject.com/u/luigiamorfini1982)\
**Post date:** [March 27, 2024, 12:50pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/4 "2024-03-27T12:50:24Z")

</div>

error console :

```auto
crispy_forms.exceptions.CrispyError: |as_crispy_field got passed an invalid or inexistent field

```

my change module … using now module : [GitHub - alsoicode/django-simple-math-captcha: An easy-to-use math field/widget captcha for Django forms.](https://github.com/alsoicode/django-simple-math-captcha)

my new code:

```auto
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm, UserChangeForm
from django import forms
from simplemathcaptcha.fields import MathCaptchaField
from django import forms
from . models import User
from django.utils.translation import gettext_lazy as _
from core.widgets import CustomDatePickerWidget

class RegisterForm(UserCreationForm):
    captcha = MathCaptchaField()
    class Meta:
        model = User
        fields = ('email', 'username', 'password1', 'password2')

class LoginForm(AuthenticationForm):
    username = forms.CharField(label='Email / Username')
    captcha = MathCaptchaField()

class PasswordChange(PasswordChangeForm):
    captcha = MathCaptchaField()

class PasswordReset(PasswordResetForm):
    captcha = MathCaptchaField()
    
class CaptchaPasswordResetForm(SetPasswordForm):
    captcha = MathCaptchaField()

class ProfileUpdate(forms.ModelForm):
    GENDER = (
        ("Male", _('Male')),
        ("Female", _('Female')),
        ("n/a", _('n/a')),
    )
    first_name = forms.CharField(label=_('First name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your first name"}), required = False)
    last_name = forms.CharField(label=_('Last name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your last name"}), required = False)
    gender = forms.ChoiceField(label=_('Gender'), choices=GENDER, widget=forms.RadioSelect, required=False)
    birthday = forms.DateField(label=_('Birthday'), required = False, widget=CustomDatePickerWidget())
    city = forms.CharField(label=_('City'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    location = forms.CharField(label=_('Location'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    phone = forms.CharField(label=_('Phone number'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    info = forms.CharField(label=_('Information user'), widget=forms.Textarea(attrs={"style": "height:160px; width:100%;"}), required=False)
    class Meta:
        model =User
        fields = ['first_name', "last_name", 'gender', 'birthday', 'city', 'location', 'phone', 'info']

class ProfileUpdatePhoto(forms.ModelForm):
    photo = forms.ImageField(required = False)
    class Meta:
        model =User
        fields = ['photo']

```

How to impossible integrated captcha in reset confirm form ?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 27, 2024, 1:01pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/5 "2024-03-27T13:01:42Z")

</div>

Look at the URL being used for that page (`/accounts/reset/<user>/set-password/`) - I do not see where you are overriding _that_ url in your urls.py, and so your custom form is not being used on that view.

---

<div class="post-metadata">

**Author:** ![luigiamorfini1982](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luigiamorfini1982/32/8836_2.png) [@luigiamorfini1982](https://forum.djangoproject.com/u/luigiamorfini1982)\
**Post date:** [March 27, 2024, 5:34pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/7 "2024-03-27T17:34:30Z")

</div>

models.py:

```auto
from django.db import models
from django.contrib.auth.models import AbstractUser, PermissionsMixin
from django.utils.translation import gettext_lazy as _
from stdimage import StdImageField
from core.utils import RandomFileName, resize_and_autorotate

class User(AbstractUser, PermissionsMixin):
        GENDER = (
               ("Male", _('Male')),
               ("Female", _('Female')),
               ("n/a", _('n/a')),
        )
        photo =StdImageField(_('Photo'), upload_to=RandomFileName("photo/"), delete_orphans=True, render_variations=resize_and_autorotate, blank=True , variations={'avatar': (120, 120, True),})
        email =models.EmailField(_('Email address'), unique=True, error_messages={'unique':_("This email has already been registered.")})
        gender =models.CharField(_('Gender'), choices=GENDER, default='n/a',max_length=50)
        birthday =models.DateField(_('Birthday'), null=True, blank=True)
        info =models.TextField(_('Information user'), null=True, blank=True)

        city =models.CharField(_('City'), null=True, blank=True,max_length=255)
        location =models.CharField(_('Location'), null=True, blank=True,max_length=255)
        phone =models.CharField(_('Phone number'), null=True, blank=True,max_length=255)

        USERNAME_FIELD = 'username'
        EMAIL_FIELD = 'email'
        REQUIRED_FIELDS = ['first_name', 'last_name', 'email']

        def save(self, *args, **kwargs):
             super(User, self).save(*args, **kwargs)

```

views.py

```auto
from django.http.response import Http404
from django.views import generic
from django.urls import reverse_lazy
from django.shortcuts import get_object_or_404, render
import braces.views
from . import forms
from . models import User

class RegisterView(generic.CreateView):
    form_class = forms.RegisterForm
    success_url = reverse_lazy('login')
    template_name = "registration/register.html"

class Profile(braces.views.LoginRequiredMixin, generic.DetailView):
    model = User
    def get_object(self):
        return get_object_or_404(User, username=self.kwargs['username'])

class ProfileUpdate(braces.views.LoginRequiredMixin, generic.UpdateView):
    model = User
    def get_success_url(self):
        return reverse_lazy("user_profile", kwargs={"username": self.request.user.username})
    def get_object(self):
        return get_object_or_404(User, username=self.request.user.username)

class ProfileUpdatePhoto(braces.views.LoginRequiredMixin, generic.UpdateView):
    model = User
    success_url = reverse_lazy('user_profile_update_photo')
    def get_success_url(self):
        return reverse_lazy("user_profile", kwargs={"username": self.request.user.username})
    def get_object(self):
        return get_object_or_404(User, username=self.request.user.username)

```

forms.py

```auto
from django.contrib.auth.forms import UserCreationForm, AuthenticationForm, PasswordChangeForm, PasswordResetForm, SetPasswordForm, UserChangeForm
from django import forms
from simplemathcaptcha.fields import MathCaptchaField
from django import forms
from . models import User
from django.utils.translation import gettext_lazy as _
from core.widgets import CustomDatePickerWidget

class RegisterForm(UserCreationForm):
    captcha = MathCaptchaField()
    class Meta:
        model = User
        fields = ('email', 'username', 'password1', 'password2')

class LoginForm(AuthenticationForm):
    username = forms.CharField(label='Email / Username')
    captcha = MathCaptchaField()

class PasswordChangeForm(PasswordChangeForm):
    captcha = MathCaptchaField()

class PasswordResetForm(PasswordResetForm):
    captcha = MathCaptchaField()
    
class CaptchaPasswordResetForm(SetPasswordForm):
    captcha = MathCaptchaField()

class ProfileUpdate(forms.ModelForm):
    GENDER = (
        ("Male", _('Male')),
        ("Female", _('Female')),
        ("n/a", _('n/a')),
    )
    first_name = forms.CharField(label=_('First name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your first name"}), required = False)
    last_name = forms.CharField(label=_('Last name'), widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': "Enter your last name"}), required = False)
    gender = forms.ChoiceField(label=_('Gender'), choices=GENDER, widget=forms.RadioSelect, required=False)
    birthday = forms.DateField(label=_('Birthday'), required = False, widget=CustomDatePickerWidget())
    city = forms.CharField(label=_('City'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    location = forms.CharField(label=_('Location'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    phone = forms.CharField(label=_('Phone number'), widget=forms.TextInput(attrs={'class':'form-control'}), required=False)
    info = forms.CharField(label=_('Information user'), widget=forms.Textarea(attrs={"style": "height:160px; width:100%;"}), required=False)
    class Meta:
        model =User
        fields = ['first_name', "last_name", 'gender', 'birthday', 'city', 'location', 'phone', 'info']

class ProfileUpdatePhoto(forms.ModelForm):
    photo = forms.ImageField(required = False)
    class Meta:
        model =User
        fields = ['photo']

```

urls.py

```auto
from django.urls import path
from django.contrib.auth import views as auth_views
from . import views
from . import forms

urlpatterns = [

    path('login/', auth_views.LoginView.as_view(form_class=forms.LoginForm), name='login'),
    path('logout/', auth_views.LogoutView.as_view(), name='logout'),
    path('register/', views.RegisterView.as_view(), name="register"),

    path('password_reset/', auth_views.PasswordResetView.as_view(form_class=forms.PasswordResetForm), name='password_reset'),
    path('password_reset_done/', auth_views.PasswordResetDoneView.as_view(), name='password_reset_done'),
    path('reset/confirm/<uidb64>/<token>/',auth_views.PasswordResetConfirmView.as_view(form_class=forms.CaptchaPasswordResetForm), name='password_reset_confirm'),
    path('reset/complete/', auth_views.PasswordResetCompleteView.as_view(), name='password_reset_complete'),
    
    path('password_change/', auth_views.PasswordChangeView.as_view(), name='password_change'),
    path('password_change/done/', auth_views.PasswordChangeDoneView.as_view(), name='password_change_done'),

    path('profile/update/', views.ProfileUpdate.as_view(template_name="user_profile_update.html", form_class=forms.ProfileUpdate), name='user_profile_update'),
    path('profile/update/photo/', views.ProfileUpdatePhoto.as_view(template_name="user_profile_update_photo.html", form_class=forms.ProfileUpdatePhoto), name='user_profile_update_photo'),
    path('profile/<str:username>/', views.Profile.as_view(template_name="user_profile.html"), name='user_profile'),
]

```

reduce html in form|crispy

```auto
{% load i18n %}

{% load crispy_forms_tags %}

{% block SITE_TITLE %} Reset Conferma Password {% endblock %}

{% block PAGE_TITLE %} Reset Conferma Password {% endblock %}

{% block content %}

{% if validlink %}
<p>Please enter (and confirm) your new password.</p>
<form action="" method="post" novalidate>
    {% csrf_token %}
    {{ form|crispy}}
   <input type="submit" value="Change my password" />
</form>
{% else %}
<h1>Password reset failed</h1>
<p>The password reset link was invalid, possibly because it has already been used. Please request a new password reset.</p>
{% endif %}
{% endblock %}

```

ok, that’s all I did with the “accounts” app.  
I don’t know how to make sure that when they confirm the password there should be a mathematical block to solve and then the password is confirmed. this is all I have.

thank you very much and have a good evening.

---

<div class="post-metadata">

**Author:** ![luigiamorfini1982](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/luigiamorfini1982/32/8836_2.png) [@luigiamorfini1982](https://forum.djangoproject.com/u/luigiamorfini1982)\
**Post date:** [March 28, 2024, 12:59pm UTC](https://forum.djangoproject.com/t/recaptcha-impossible-insert-in-form-reset-confirm/29527/8 "2024-03-28T12:59:38Z")

</div>

fixed, solved problem

 ![image](https://us1.discourse-cdn.com/flex026/uploads/djangoproject/original/3X/7/d/7dcbfd060863a7b61f95d001dd17483c22c5793b.png)

my remove : path(“accounts/”, include(“django.contrib.auth.urls”)),

solved problem

thanks.
