1👍
✅
Most probably the form
is not going to password_reset_confirm.html
since django-rest-framework does not include the form
in the context
of the PasswordResetConfirmView
by default.
Currently, the thing you can do is to create a custom PasswordResetConfirmView
by inheriting it in a sub class and pass the form
to the template context, using form_class
attribute so:
from django.contrib.auth.forms import SetPasswordForm
from django.contrib.auth.views import PasswordResetConfirmView
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_protect
from django.views.decorators.debug import sensitive_post_parameters
class CustomPasswordResetConfirmView(PasswordResetConfirmView):
form_class = SetPasswordForm
success_url = reverse_lazy('password_reset_complete')
template_name = 'users/password_reset_confirm.html'
@method_decorator(sensitive_post_parameters('new_password1', 'new_password2'))
@method_decorator(csrf_protect)
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = self.form_class(user=self.request.user)
return context
Then in urls.py
:
urlpatterns = [
# .......
path('password-reset-confirm/<uidb64>/<token>/', CustomPasswordResetConfirmView.as_view(), name='password_reset_confirm'),
# .......
]
You can provide any success_url
according to your need.
Source:stackexchange.com