python - Updating User Password in Django with Class Based Views -
i'm tring write view administrator update password of user, using class based views , model setpasswordform of django.
my views.py
class usersetpasswordupdateview(grouprequiredmixin, formview): form_class = forms.setpasswordform model = user template_name = 'app/admin/object_update.html' success_url = reverse_lazy('portal:admin_user') group_required = u"administrator" def get_form_kwargs(self): kwargs = super(usersetpasswordupdateview, self).get_form_kwargs() kwargs['user'] = user.objects.filter(pk=self.kwargs['pk']) return kwargs update_change_password = usersetpasswordupdateview.as_view()
my urls.py
url(r'^app/admin/update-user-pass/(?p<pk>[0-9]+)$', update_views.update_change_password, name='update_change_password'),
and don't show errors, go success_url
, password don't updated.
your view based on formview. doesn't have knowledge of model forms, , doesn't data other check valid. setpasswordform changes password when form saved, view never this.
you override form_valid
call form.save()
explicitly, better use more appropriate base class such updateview you.
Comments
Post a Comment