Django: Getting Started Transcripts
Chapter: Users and Account Management
Lecture: Changing passwords
Login or
purchase this course
to watch this video and the rest of the course contents.
0:01
Okay, Let's take a look at the password change process. I'll start by showing you my prewritten password change form.
0:11
Remember Django has a view for this already so you have to name the file exactly this. The good news is you don't have to write a view.
0:20
The bad news is you do have to write the template. Like the login page a form object gets passed into the context.
0:28
If there are errors in the form like the user has attempted something previously and been
0:33
sent back to the page then the form objects error attribute will have information in it. I'm handling that here beginning on line 5.
0:43
In the error case the forum will have some text above that indicates errors need to be corrected the div on line six.
0:49
If there aren't errors then some instructions are shown telling the user they have to enter their old password and then their new password twice.
1:01
Just like the login page, you start out with some CSRF magic. Unlike the login page, I'm doing something a little different here.
1:12
Instead of just doing form.sp I'm using a bunch of bootstrap to make the page far prettier. In order to get that prettiness,
1:21
I'm using bootstraps class called form group. The first group contains an input field for the old password.
1:29
This first if embedded inside the class tag checks if there are errors associated with this
1:35
field like for example the user didn't get their old password correct and if so includes the is invalid class in this forms stylization.
1:47
The second if tag checks if there's a value in this field. If so, it includes it in the input tags value attribute displaying the old value
1:58
The third if tag also checks for errors displaying a div with the actual error information inside of it.
2:06
HTML is so verbose, two more input fields to go each input field gets its own form group.
2:13
So here's another form group. This one is for the users new password. This is also an HTML input field has similar if tags to the one above
2:23
making sure that the field shows the appropriate errors, existing values and some help text. And then this last one is pretty much the same
2:34
as the previous one, except instead of being new password one, this is new password two.
2:39
The password change view will validate whether these two fields contain the same information.
2:46
Top it all off with a submit button and you're ready for the next template.