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
0:02 so let's actually be able to register for the site.
0:06 Well, first of all I click here. Hmmm.
0:09 Doesn't really take us there.
0:10 We actually have the route in place
0:12 we just haven't put it up here
0:13 so let's say account/register.
0:17 Try again. Okay, now we have our register form here.
0:21 We have our name, our email address, and password.
0:23 And we can submit it.
0:25 And if you look at the browser at the top
0:26 it is submitting stuff back to the server
0:29 bunch of empty things. But if we look in here
0:34 this is what we get when we click
0:36 the link in the navigation.
0:38 This is what happens when we submit the form
0:40 'cause one is a GET and one is a POST right?
0:43 Let's just print out the data that we're passing in.
0:45 So, we're going to say request
0:46 and the way we get this is...
0:49 well that's not very helpful is it?
0:52 There's four different places that this data can come from.
0:56 Let's enhance this a bit.
0:58 If you have a smart editor like PyCharm
1:02 we're going to say this is a request
1:03 and make sure you import that from Pyramid.
1:06 Oh, let's try this again.
1:07 Comes from, oh yeah we've got POST
1:10 capital Post. We also have Get
1:15 Also have matchdict
1:16 So let's uh, let's real quick print out
1:20 what's coming in here.
1:23 Alright, remember you have to rerun it
1:24 for the Python bits to take effect.
1:26 If I put my name as Michael, my email address
1:29 is and the password
1:34 is amazing, it's just going to be the letter a.
1:37 If we go back over here let's see what we got.
1:39 We have this thing called a multidict
1:41 but as far as you're concerned
1:42 you might as well just treat it like a dictionary.
1:43 One thing they do that's pretty slick
1:44 is when you print it out if there's a password or something
1:48 it'll star it out so it's anonymous.
1:50 Even though I told you it still is just the letter a.
1:53 So the name, it's passing though just like that.
1:55 Email's passing through, like that and password.
1:58 And then Get, Get doesn't have anything.
2:01 But if we had something up here like:
2:03 question mark source equals promo, and we do the same thing
2:10 you can see in this case those right there
2:12 now our Get has the source.
2:13 So Get is the query string
2:16 and then the matchdict is actually
2:18 the data coming from the route.
2:20 If we look at the route definition
2:22 there's nothing here, but if we had
2:24 I don't know, something like mode
2:27 or some additional data
2:28 like we are with our package name up here.
2:32 Where were kind of come up here and say this is going to be:
2:35 /newuser, right? That would be the mode.
2:42 Now if we look back you can see the matchdict
2:43 has that mode. These pieces coming through over there.
2:48 Okay, super. So this is the data
2:50 that's being provided to us, now our job is to take
2:53 well, in this case, just the POST data
2:56 and use that to actually create the user
3:00 to register the user.
3:01 So that's going to be our next step.