Hi I want to use a snippet with Class-based views, but instantion of this form must pass a User object ex.
theform = forms.PasswordReset(request.user,request.POST)
And here is a question, how to do this with Class-based views:
class UserChangePassword(FormView):
form_class = PasswordReset
template_name = 'profile/change_password.html'
success_url = reverse_lazy('user_account')
You have two options here:
Write your own get_form method.
def get_form(self, form_class):
return form_class(self.request.user, self.request.POST)
Write your own get_form_kwargs and update form's code.
def get_form_kwargs(self):
kwargs = super(UserChangePassword, self).get_form_kwargs()
kwargs.update({'user': self.request.user, 'post': self.request.POST})
return kwargs
In this case you also need to update form to work properly with kwargs pairs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With