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

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So we've wired up our form through the register page
0:04 and it calls the GET version when we do an initial load
0:08 and it calls this post version when we submit the form.
0:11 So this is really nice, it lets us separate the data access
0:14 and various things we do to initially populate the form
0:17 from the thing we actually do to process the request.
0:21 In this case that's the request to register for the site.
0:24 now the next question is well, how do I get the data they gave us from over here?
0:29 We had an email and we had a password and we had confirm password.
0:33 How do we get that?
0:36 So over here we are going to go to the request,
0:39 now the request was stored by the base controller onto this class,
0:44 so we can just say self.request and there is a way to access the post data,
0:48 there is a way to access the query strings,
0:51 there is a way to access the routes
0:54 and all of those can communicate data to this method,
0:57 so for now we are just going to focus on POST
0:59 and later we'll look at the way to unify this
1:01 and sort of forget this is ever a decision you make,
1:04 where did the data come from, for example.
1:06 So, on the request object, there is a POST dictionary,
1:10 standard, more or less standard,
1:11 it's a multidict but a standard dictionary type of access,
1:14 so we want to get a hold of the email, and the best way to do it is to use the GET,
1:19 because if for some reason this field or this key is missing from this POST,
1:25 it will crash the site if we don't do a GET,
1:27 if we just do ('email'), but this will just make it Null
1:30 if it's not there, so we want to do this again for a few things.
1:33 OK and let's just print this out just to see that the data is getting here,
1:38 we are not going to do anything with it yet, but we'll print out the data.
1:44 This is going to be, password is going to be the letter "a",
1:51 this is going to be also the letter "a",
1:54 let's register so we get "oh would you like to save this?"
1:58 Not right now, check this out, we've passed our data in,
2:02 it's jeff and I made this mismatch here just to be silly,
2:05 a little lowercase "a" and uppercase "A",
2:08 so this is how we get the data passed over
2:10 let's pull this up so you see it together,
2:12 anytime we post the data, it just gets stored in this POST dictionary,
2:15 which we can access however we want to do with dictionary access.