Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: User input and HTML forms
Lecture: Register POST action

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We have our register form in place so let's actually be able to register for the site. Well, first of all I click here. Hmmm.
0:10 Doesn't really take us there. We actually have the route in place we just haven't put it up here so let's say account/register.
0:18 Try again. Okay, now we have our register form here. We have our name, our email address, and password. And we can submit it.
0:26 And if you look at the browser at the top it is submitting stuff back to the server bunch of empty things. But if we look in here
0:35 this is what we get when we click the link in the navigation. This is what happens when we submit the form 'cause one is a GET and one is a POST right?
0:44 Let's just print out the data that we're passing in. So, we're going to say request and the way we get this is... well that's not very helpful is it?
0:53 There's four different places that this data can come from. Let's enhance this a bit. If you have a smart editor like PyCharm
1:03 we're going to say this is a request and make sure you import that from Pyramid. Oh, let's try this again. Comes from, oh yeah we've got POST
1:11 capital Post. We also have Get Also have matchdict So let's uh, let's real quick print out what's coming in here.
1:24 Alright, remember you have to rerun it for the Python bits to take effect. If I put my name as Michael, my email address
1:30 is michael@talkpython.fm and the password is amazing, it's just going to be the letter a. If we go back over here let's see what we got.
1:40 We have this thing called a multidict but as far as you're concerned you might as well just treat it like a dictionary.
1:44 One thing they do that's pretty slick is when you print it out if there's a password or something it'll star it out so it's anonymous.
1:51 Even though I told you it still is just the letter a. So the name, it's passing though just like that. Email's passing through, like that and password.
1:59 And then Get, Get doesn't have anything. But if we had something up here like: question mark source equals promo, and we do the same thing
2:11 you can see in this case those right there now our Get has the source. So Get is the query string and then the matchdict is actually
2:19 the data coming from the route. If we look at the route definition there's nothing here, but if we had I don't know, something like mode
2:28 or some additional data like we are with our package name up here. Where were kind of come up here and say this is going to be:
2:36 /newuser, right? That would be the mode. Now if we look back you can see the matchdict has that mode. These pieces coming through over there.
2:49 Okay, super. So this is the data that's being provided to us, now our job is to take well, in this case, just the POST data
2:57 and use that to actually create the user to register the user. So that's going to be our next step.


Talk Python's Mastodon Michael Kennedy's Mastodon