Python for Entrepreneurs Transcripts
Chapter: Build web apps with Pyramid: Applied web development
Lecture: Register on the site (handle GET section) demo

Login or purchase this course to watch this video and the rest of the course contents.
0:03 Let's come back to our web app
0:04 and add the ability for people to register for our account.
0:07 Now, I've done a little bit of pre-work,
0:09 so we don't have to do everything from scratch,
0:11 I've created an account controller and down here
0:14 I've created the folder, input three entirely empty page templates,
0:19 or views down here, and I've used our add controller routes
0:22 and registered that controller for all the standard routes
0:25 that we have for other controllers.
0:28 Over here you can see we have this /accounts view,
0:32 and we have a /accounts/sign in view.
0:36 Now, let's do the same for register, so we are going to come over here
0:40 and we are just going to say register,
0:43 now notice, we are going to have to come back and make a change to this,
0:46 this is not going to be sufficient for the way we want to write our code,
0:50 technically we could get away with this
0:53 but we are going to want to add a second method in a moment,
0:55 but let's just start here, this is going to be our, let's just put a note to ourselves,
0:59 "GET /account/register", OK, let's just make sure this works.
1:08 Here we are in our home page, notice I've added a register option up here
1:12 and if I click it, it just takes us to account/register, hey create an account,
1:16 so the first thing we have to do is create the form,
1:19 so we are going to go over here to our register page
1:22 and notice we are using our view layout, our shared layout
1:26 and notice how and completely simple and wonderful this is,
1:29 this is the full content of this page, let's start by adding a form,
1:33 so remember the form action is going to be empty
1:36 and the method is going to be POST, it's how we are going to submit the form,
1:40 and then we want to put a couple of inputs in here,
1:43 so we can have an input of type text and we can set the value,
1:48 we are going to put something here in a minute,
1:51 we are going to have the input of type, say this is, let's go and give these names,
1:56 so the name, it's going to be email, and this name is going to be password,
2:02 and this can be confirm_password, something like that.
2:05 Now obviously, we don't want the password type to be text,
2:09 we want it to be those little dots, that obscures the text that's in there
2:13 so we can do that by putting that to be password type,
2:16 and then ultimately we want to have some mechanism for submitting this back
2:19 so we'll add a button and you can set the type to be submitted
2:23 and here we'll just add the message register.
2:26 Now just prepare yourself, this is not going to look very good,
2:29 it's going to look probably straight out of 1994,
2:32 but we'll be able to apply some styles and techniques to it later
2:37 when we get to the front-end frameworks to make it really nice-looking.
2:40 So if we refresh the page, we now see this here, so what is this?
2:46 OK, so let's try to make this little nicer,
2:49 notice that we don't know what's in here, there is a couple of ways we could do it,
2:53 we could have the text preceding it,
2:55 saying like "email address:" and then put the form, "password:", put the form,
2:59 and so on, or we could make it a little cleaner and try to put this all in one,
3:04 there are some drawbacks to this but I kind of like it,
3:07 we'll say email address, we could put a placeholder here,
3:10 and if we do that, when I refresh you can see it says email address
3:13 but of course as you type, it goes away.
3:16 That's lovely. So let's go down here and put the placeholder,
3:19 and this will be "password" and then this will be "confirm password", like this,
3:26 alright, that's looking good, and now we just need some new lines on it here,
3:32 so everything wraps, like I said, everything is looking straight out of 1994 here,
3:37 I guess it's not quite that bad, but it doesn't look great,
3:40 maybe we could put just a little bit of padding before we carry on,
3:46 so I am going to create a class called standard form
3:48 and any of the standard forms we are are going to put padding onto their inputs,
3:52 so let's go down here and say "any time we have a standard form and it has an input",
3:57 whether that is text or whatever, we are going to put a margin,
4:00 I said padding, but let's put margin of 10 px.
4:03 Let's do the same for buttons.
4:06 So we can, remember, this is or if we separate with the comma,
4:09 so if it's contained within standard form and it's input, it has a margin,
4:13 if it's contained within a standard form and it's a button, also this, so let's see how that works.
4:17 Little better, it's not amazing, but it'll have to do.
4:21 Let's add one more thing here for just the inputs,
4:26 say the width is going to be 350 px.
4:30 There we go, like I said, not amazing but I think this will totally do for a form,
4:34 now if we try to register, what happens?
4:37 It looks like it works, we can put something in here
4:40 and it refreshes and whatever I put in there just went away.
4:43 But it is actually posting back, and being processed,
4:46 up here, I can show you that, like so,
4:49 if I come over here and do a little print, calling register,
4:53 remember I've got to rerun this app to see Python changes,
4:56 and we go over here and click it, and see it is calling it
5:02 but we are not doing anything to get the data,
5:04 we are not obviously processing anything,
5:06 now we want to get to our GET/POST/redirect pattern.