I do a simple user registration on Django. Registration and user login works. Now I want the user to log in to his profile and was able to change his password. For this, I used PasswordChangeForm. And that's what I'm doing. Views.py file

from django.contrib.auth.forms import PasswordChangeForm from django.views.generic.edit import FormView class ChangeFormView(FormView): form_class = PasswordChangeForm success_url = '/' template_name = 'app/edit_pass.html' def form_valid(self, form): form.save() return super(ChangeFormView, self).form_valid(form) 

file urls.py

 from django.conf.urls import url from . import views urlpatterns = [ # некоторые урлы здесь url(r'^edit_pass/$', views.ChangeFormView.as_view()), ] 

in the profile.html file I prescribe a link to change the password

 <a href="/edit_pass">change a password</a> 

I have a simple form in the edit_pass.html file.

 <form action="" method="POST"> {% csrf_token %} {{form.as_p}} <button type="submit">edit a password</button> </form> 

According to the results, I get TypeError error at / edit_pass / How to do it right?

    1 answer 1

    Views.py file

     from django.views.generic import UpdateView from django.contrib.auth.forms import PasswordChangeForm class ChangeFormView(UpdateView): form_class = PasswordChangeForm template_name = 'app/edit_pass.html' success_url = '/index' def get_object(self, queryset=None): return self.request.user def get_form_kwargs(self): kwargs = super(ChangeFormView, self).get_form_kwargs() kwargs['user'] = kwargs.pop('instance') return kwargs 
    • Accept your answer - Mae