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 real quick print out what's coming in here. Alright, remember you have to rerun it
1:25 for the Python bits to take effect. If I put my name as Michael, my email address is michael@talkpython.fm and the password
1:35 is amazing, it's just going to be the letter a. If we go back over here let's see what we got. We have this thing called a multidict
1:42 but as far as you're concerned you might as well just treat it like a dictionary. One thing they do that's pretty slick
1:45 is when you print it out if there's a password or something it'll star it out so it's anonymous. Even though I told you it still is just the letter a.
1:54 So the name, it's passing though just like that. Email's passing through, like that and password. And then Get, Get doesn't have anything.
2:02 But if we had something up here like: question mark source equals promo, and we do the same thing you can see in this case those right there
2:13 now our Get has the source. So Get is the query string and then the matchdict is actually the data coming from the route.
2:21 If we look at the route definition there's nothing here, but if we had I don't know, something like mode or some additional data
2:29 like we are with our package name up here. Where were kind of come up here and say this is going to be: /newuser, right? That would be the mode.
2:43 Now if we look back you can see the matchdict has that mode. These pieces coming through over there. Okay, super. So this is the data
2:51 that's being provided to us, now our job is to take well, in this case, just the POST data and use that to actually create the user
3:01 to register the user. So that's going to be our next step.


Talk Python's Mastodon Michael Kennedy's Mastodon