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 and it calls the GET version when we do an initial load
0:09 and it calls this post version when we submit the form. So this is really nice, it lets us separate the data access
0:15 and various things we do to initially populate the form from the thing we actually do to process the request.
0:22 In this case that's the request to register for the site. now the next question is well, how do I get the data they gave us from over here?
0:30 We had an email and we had a password and we had confirm password. How do we get that? So over here we are going to go to the request,
0:40 now the request was stored by the base controller onto this class, so we can just say self.request and there is a way to access the post data,
0:49 there is a way to access the query strings, there is a way to access the routes and all of those can communicate data to this method,
0:58 so for now we are just going to focus on POST and later we'll look at the way to unify this and sort of forget this is ever a decision you make,
1:05 where did the data come from, for example. So, on the request object, there is a POST dictionary, standard, more or less standard,
1:12 it's a multidict but a standard dictionary type of access, so we want to get a hold of the email, and the best way to do it is to use the GET,
1:20 because if for some reason this field or this key is missing from this POST, it will crash the site if we don't do a GET,
1:28 if we just do ('email'), but this will just make it Null if it's not there, so we want to do this again for a few things.
1:34 OK and let's just print this out just to see that the data is getting here, we are not going to do anything with it yet, but we'll print out the data.
1:45 This is going to be jeff@jeff.com, password is going to be the letter "a", this is going to be also the letter "a",
1:55 let's register so we get "oh would you like to save this?" Not right now, check this out, we've passed our data in,
2:03 it's jeff and I made this mismatch here just to be silly, a little lowercase "a" and uppercase "A", so this is how we get the data passed over
2:11 let's pull this up so you see it together, anytime we post the data, it just gets stored in this POST dictionary,
2:16 which we can access however we want to do with dictionary access.


Talk Python's Mastodon Michael Kennedy's Mastodon