Building data-driven web apps with Flask and SQLAlchemy Transcripts
Chapter: Course conclusion
Lecture: GET-POST-Redirect

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The next important idea that we talked about was
0:02 HTML forms accepting user input.
0:05 Switching between different
0:07 view methods based on the HTTP verb
0:09 like one for GET and one for POST
0:11 and all of that really evolved around this
0:13 get/post/redirect pattern
0:15 or post/get/redirect if you believe Wikipedia.
0:18 And the idea was that
0:20 we're going to go and do a GET
0:21 a user with their web browser and their laptop here
0:24 is going to do a get for accounts/register.
0:26 The servers are going to respond with
0:27 just that form probably not filled out at all.
0:31 Then they fill that out
0:32 with my first name's this, my last name's that
0:34 my email I'm going to use this such and such and so on
0:36 and then they press save or create account or whatever
0:39 and it does a post back to the same URL.
0:41 It's a different view method.
0:43 We're going to save that validated data to the database
0:46 and if we're all happy then we're going to send them
0:48 a redirect to some page.
0:49 Like redirect to welcome or redirect to slash account
0:52 or whatever it is they're signing in for.
0:54 And this avoids that weird error
0:56 where if you try to refresh a page it says warning
0:58 you're going to resubmit it.
0:59 It just makes everything super nice and clear
1:02 and this definitely a pattern you want to apply.
1:04 It's really easy with Flask and the decorators
1:06 to distinguish between the different steps
1:09 with different methods just using
1:11 the methods part of the decorator
1:13 in blueprint.route or app.route.