TIL/2020–11–29

Renzo Regio
2 min readNov 30, 2020

Today, I will talk about what I said on my previous TIL. What will happen when we select change password on the form?

The answer is that it will definitely change the password of the user, BUT after clicking the button there will be an error. Because the form wouldn’t know where to go. For this I used another method called get_success_url and it takes on the argument of self. This will also be done inside the ChangePasswordView class that we made.

There are actually two ways of doing it:

  1. Providing a success_url and specifying where to redirect.

2. Or we could use the method of get_success_url and customize it even further by adding a message.

If you remember, on my users models I already made the get_absolute_url method: This is in the model of the User. In models.py.

So what we can do is add the method:

And this redirects us back to our profile page with the message of

If we just do success_url we wouldn’t be able to add a message like the one above. Unless we add a SuccessMessageMixin which makes it easier but personally, I prefer seeing what is happening rather than just using all the magic and wonders of Django.

Code:

--

--