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

Login or purchase this course to watch this video and the rest of the course contents.
0:01 We saw that we have our basic form
0:02 and it does call whenever we post it, it calls back to this page
0:06 but the point of this page is really just to create the form, this is the GET part.
0:10 So what we can do is let's put a little note here, "calling register via GET",
0:16 and recall that we can come here
0:18 and we can set the request_method to be just GET.
0:22 Now let's look again.
0:24 Will it work if I click register? Yes, the GET is fine but watch this, boom, 404.
0:29 There is nothing that will respond to /account/register POST, right?
0:34 So what we've been able to do here, save this method, this is only the GET part,
0:39 this only registers it, now let's have the part that actually processes the data
0:44 that comes in from the form.
0:47 So we are going to come down here, we are going to have one that's called POST,
0:51 and I am going to try to make a mistake here
0:53 and you will see something weird is going to go on.
0:57 Just look at this screen for a minute, pause the video if you wish,
1:00 and we've got this method responding to GET, this method responding to POST,
1:07 and it says different stuff here... GET, POST.
1:10 What do you think it's going to happen if I run this?
1:13 If I come over here if I click on this, I click here,
1:16 this is not going to turn out in an amazing way for us.
1:20 Boom, not found, huh, that's weird, and yet,
1:23 if I come over here and submit it, it actually is working,
1:27 you can see "Creating call register via POST",
1:29 so here is something you have to be super careful of
1:31 and I run into it every now and then and then I'll "oh, what was I thinking,
1:35 why was I not paying attention?"
1:37 Some languages, when you have classes allow you to have multiple methods
1:42 with the same name and you are overwriting them by signature or something like this,
1:47 this is not a concept that exists in Python,
1:50 we need to, if these two methods are going to coexist,
1:53 they have to have different names, basically what happened was
1:55 this method was created and then it was ejected from the class
1:58 and then replaced with the only the one that handles POSTs.
2:01 That was not amazing, so I wanted to make sure you saw that
2:04 because that's something I am sure you'll run into,
2:07 so I'm going to call this register_get and register_post, and yet if I try to run this,
2:12 it's going to say well there is nothing at /account/register,
2:15 yet there is something at /account/register_get,
2:19 so what we have to do is we have to say tie these back together
2:22 and say "no no, these both respond to the register URL"
2:26 but they have to have different names so they can coexist,
2:28 so we set the name of this here to be like so.
2:34 Now of course rerun the Python, now everything should be working good
2:38 I click on register, I get this, calling via GET, click the button, call it via POST.
2:42 Great, now that we are calling this via POST,
2:45 the next thing to do is to figure out well what data did they send us?
2:49 What's your email, what's your password? Things like that.