Hey,
I’m tryining to make a custom form of the ResetPasswordView from Django.
I did everything as it should and this error appears by loading the page.
'CharField' object has no attribute 'as_widget'
heres my code
forms.py
class CaptchaPasswordResetForm(PasswordResetConfirmView):
new_password1 = forms.forms.CharField(max_length=100, widget=forms.forms.PasswordInput(attrs={"class": "form-control", 'type':'password'}))
new_password2 = forms.forms.CharField(max_length=100, widget=forms.forms.PasswordInput(attrs={"class": "form-control", 'type':'password'}))
class Meta:
model = User
fields = ('new_password1', 'new_password2')
heres my views.py
class password_reset_view(PasswordResetConfirmView):
form_class = CaptchaPasswordResetForm
success_url = reverse_lazy('home:login')
herey my urls.py (the one in the base)
from StartSite.forms import NewPasswordResetForm
from StartSite.forms import CaptchaPasswordResetForm
from django.contrib import admin
from django.urls import path, include
from django.urls.base import reverse_lazy
from django.contrib.auth import views as auth_views
from StartSite.views import PasswordResetView, password_reset_email_view
urlpatterns = [
path('admin/', admin.site.urls),
path('', include('StartSite.urls')),
path('reset_password/',
password_reset_email_view.as_view(template_name="home/password_reset.html", form_class=NewPasswordResetForm),
name="reset_password"),
path('reset_password_sent/',
auth_views.PasswordResetDoneView.as_view(template_name="home/password_reset_sent.html"),
name="password_reset_done"),
path('reset/confirm/<uidb64>/<token>/',
PasswordResetView.as_view(template_name="home/password_reset_form.html", form_class=CaptchaPasswordResetForm),
name="password_reset_confirm"),
path('reset_password_complete/',
auth_views.PasswordResetCompleteView.as_view(template_name="home/password_reset_done.html"),
name="password_reset_complete"),
]
and heres my html code (the important part):
<form method="post" class="id_email_change_form">
{% csrf_token %}
<p>Please enter your new password</p>
<h6 class="mb-0">New Password</h6>
<div class="pw_space2"></div>
{% render_field form.new_password1 class="form-control" type="password" placeholder="New Password" id="phone-form7-b" data-form-field="password"%}
<div class="pw_space"></div>
<h6 class="mb-0">Repeat New Password</h6>
<div class="pw_space2"></div>
{% render_field form.new_password2 class="form-control" type="password" placeholder="Repeat New Password" id="phone-form7-b" data-form-field="password"%}
{{form.errors}}
<div class="pw_space2"></div>
<button style="background-color:#7231aa; border:#7231aa; color:white;" class="btn btn-secondary " type="submit">Change Password</button>
<a style="background-color:#7231aa; border:#7231aa; color:white;" class="btn btn-secondary " target="__blank" href="{%url 'home:profilesettings'%}">Cancel</a>
</form>
I have something similar with the first form where you can just put in your email and then the links gets sended, I tried to remove the fields in the render so that theres just the render tag and the name of the form and the erorr disappeared but the form also. So the input field isnt there anymore. I think its something wrong with the way im doing this and the erorr for both is the same