Im trying to make a custom change password page but the page with the “PasswortConfirmView” prints this error
Internal Server Error: /reset/confirm/MQ/atg5tq-aa6bcab1c34d1228cdd1970aaaa45252/
Traceback (most recent call last):
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
response = get_response(request)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
response = response.render()
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\response.py", line 105, in render
self.content = self.rendered_content
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\response.py", line 83, in rendered_content
return template.render(context, self._request)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\backends\django.py", line 61, in render
return self.template.render(context)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 170, in render
return self._render(context)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 162, in _render
return self.nodelist.render(context)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 938, in render
bit = node.render_annotated(context)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\django\template\base.py", line 905, in render_annotated
return self.render(context)
File "C:\Users\Finn\AppData\Local\Programs\Python\Python39\lib\site-packages\widget_tweaks\templatetags\widget_tweaks.py", line 220, in render
bounded_field.field.widget.input_type = v.resolve(context)
AttributeError: 'str' object has no attribute 'field'
forms.py
class CaptchaPasswordResetForm(SetPasswordForm):
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'}))
forms.py
urls.py
from StartSite.views import password_reset_view
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>/',
password_reset_view.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"),
]
views.py
class password_reset_view(PasswordResetConfirmView):
form_class = CaptchaPasswordResetForm
success_url = reverse_lazy('home:login')
template
<form method="post" class="id_password_reset_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" 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" 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>