Adding a CMS to Your Flask Web App Transcripts
Chapter: Course conclusion
Lecture: Review: ViewModels
0:00 we made heavy use of this view model pattern and I use this in all of my websites. I find it massively helpful. It makes our view methods much simpler.
0:09 It makes it easier to test the validation and data exchange logic. All sorts of things are beautiful about this view model pattern.
0:17 So the general idea is that we have a request coming into the server.
0:20 And here we have http post for register and this indicates they're submitting some form data
0:26 Probably. They're filling out the register form and hitting. Sign me up. The reason I put that you're all there is the view model
0:33 is most valuable. When you're doing complex data exchange and back and forth with the usual like this, it's valuable everywhere.
0:40 But this is where it has the most value. A lot of times for these types of functions,
0:45 what you'll see is like some huge long view or action method inside, hopefully not apt up ey along with everything else.
0:52 But often that's the case. You see, some giant function that's doing everything is doing. The validation is doing the data exchange and conversion.
1:02 It's doing the view stuff, all of it But with this view model pattern, we can take much of that and put it over into,
1:08 ah, view model and write a much cleaner, simpler action or view method, as we just saw with that redirect,
1:15 and then just let those two things talk to each other and so helps isolate the different parts of the code that we got to run.
1:22 The validation data exchange can be its own thing, and then what to do with it if it's valid or invalid in the action method
1:28 Also, again, it makes testing that view model stuff much easier, because if you don't have to figure out how to call the action method through the
1:36 Web requests and all that kind of stuff, so it does make things simpler in that regard as well.