Adding a CMS to Your Flask Web App Transcripts
Chapter: The redirects (our bit.ly)
Lecture: Concept: GET-POST-Redirect
0:00 before we get to writing the code. Actually, edit are re drinks or for that matter,
0:05 are pages as well. 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 and there way
0:19 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 are
0:25 things. How does that work? Well, we have our server, and we have our database out there somewhere.
0:31 There's, ah, user who wants to talk to our site in the assumption here is they're going toe edit one of these redirects,
0:37 or they're going to create an account or something like that. They're gonna register for an account.
0:42 So the first thing that they need to do to get started as they need to see that page that has the form like we're gonna register.
0:48 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 going to do an http get requests against the server for slash accounts, slash register, and that's going to show the form on their page.
1:01 And then they're going to say, Well, my name is Michael, and my email address is Michael a talk by then Daughter Fam and so on.
1:06 And they added that locally, and then we're gonna save that back. So too, do the saving into an HDB post back to the same euro.
1:14 The server's gonna look at that. Go. That means they want to save stuff. Let's validate it. And then if it works,
1:18 we're gonna save it. And then finally, instead of leaving them on this page, they've just registered. They've just created account.
1:24 What do we want to do? Probably send them to slash accounts or some sort of welcome page.
1:30 We're going to send them a redirect request and http found as we've already been doing two slash Welcome, Welcome your account.
1:38 Here's what you gotta do to get started using our service. 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 to 3, they're gonna get a message that you have to read it again.
1:54 Post this back again. And then eventually, when it's valid, they move on to the redirect stage. This is how I think of it.
2:00 I get the form I edit the form I save the former. I go on, This is actually a well known pattern mentioned on Wikipedia.
2:07 But they have it wrong. In my opinion. They call it post, then redirect, then get well, what do you posting? You got to start to get the thing,
2:14 Teoh actually post so anyway, they call it Post Re drag, get. But it's a very well known pattern around organizing our code and the way
2:22 that we process people editing data on the web. So we're going to use this for our admin section,