Adding a CMS to Your Pyramid Web App Transcripts
Chapter: Redirects and the admin section
Lecture: Concept: GET-POST-Redirect flow

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before we get to writing the code, actually edit our redirects, or for that matter, are pages as well,
0:07 I want to review this design pattern, this concept that you may be familiar with, but you might not be.
0:12 And it's super nice for how we organize your code. I still see lots of Web apps out there not explicitly using this
0:18 and they're way harder to understand and work with because of it. So the idea is we're going to use this get post redirect pattern to edit our things.
0:26 How does that work? Well, we have our server, and we have our database. Out there somewhere, there's a user who wants to talk to our site and
0:34 the assumption here, is they're going to edit one of these redirects. Or they're going to create an account or something like that.
0:41 They're gonna register for an account. So the first thing that they need to do to get started is they need to see that page that has the form.
0:47 Like we're gonna register. So what is your name? What is your email? What do you want your password to be? Things like that.
0:52 So they're gonna do an http get request against the server for '/accounts/register', and that's gonna show the form on their page.
1:01 And then they're going to say, Well, my name is Michael and my email addresses michael@talkpython.fm and so on.
1:06 And they edit that locally, and then we're gonna save that back. So to do the save, their going to do an http post back to the same url.
1:14 The server's gonna look at that and go, "That means they want to save stuff. Let's validate it. And then if it works, we're gonna save it".
1:19 And then finally, instead of leaving them on this page, they've just registered. They've just created an account
1:25 What do we want to do? Probably send them to '/accounts' or some sort of welcome page
1:30 They're going to send them a redirect request an http found as we've already been doing to '/ welcome'
1:37 Welcome to your account! Here's what you gotta do to get started using our service.
1:41 So it's a 'get, post, redirect' that is very typically the way that this works.
1:46 If for some reason the data doesn't validate, they're going to stay on Step 2-3.
1:51 They're gonna get a message that you have to edit it again, post this back again.
1:55 And then eventually, when it's valid, they move on to the redirect stage.
1:58 This is how I think of it. I get the form. I edit the form. I save the form, and I go on.
2:03 This is actually a well known pattern mentioned on Wikipedia, but they have it wrong in my opinion. They call it post, then redirect, then get.
2:12 Well, what are you posting? You got to start to get the thing to actually post.
2:16 So anyway, they call it post, redirect, get, but it's a very well known pattern around
2:21 organizing our code and the way that we process people editing data on the web. So we're going to use this for our admin section, of course.


Talk Python's Mastodon Michael Kennedy's Mastodon