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

Talk Python's Mastodon Michael Kennedy's Mastodon