Python Web Apps that Fly with CDNs Transcripts
Chapter: Integrating Static Content
Lecture: Project code structure
0:00 Let me walk you through the codes because I have a very structured layout for the way I like to put my web apps together.
0:12 And a lot of how the structure is tells you exactly where to look to make changes, who are to understand what we're working with. So we have our app.
0:22 This is a standard flask. There's not a whole lot going here.
0:26 But notice in this register blueprints, we've broken up all the different HTML or URL endpoints
0:33 into separate files all within the views folder using the blueprint pattern from Flask.
0:40 I really, really don't like putting just everything into one file.
0:43 It makes it super hard to work with, super hard to know where to go and how to organize things. So I use this blueprint model.
0:50 So for example, over here in home, we have a blueprint. And instead of saying app.get, we say blueprint.get and we bring that back in.
0:58 So if you care about stuff on the homepage, it's here, you care about the URLs, about
1:02 videos, like here's the video categories or playing a video, it's in this videos folder, all that within the views. Now that structure tells you a lot.
1:13 I'm using this pattern called a view model pattern. And over in the view models folder, well, there's a mirror image of the way that the
1:22 the views themselves are structured. So we have a videos folder, we have a home folder
1:28 and a feed folders. And in the videos, we have a category view model, a play view model
1:34 down here, we have a get, get for adding categories, and we have search, for example, a search
1:43 view model to use files for grouping them. And then we have these view models. And we
1:50 We have a separate class, for example, this one that knows the data that we're trying to work with and how to exchange it with the HTML templates.
2:00 Speaking of templates, go over here. First of all, there's a problem with the way PyCharm understood our project. So see how this is gray?
2:09 It should be marked as a special template thing so we can right-click, at least in PyCharm Pro.
2:15 I don't know if you can do this in standard community PyCharm. So, say market as a template directory,
2:21 and that tells it this is where the templates are, it creates some like auto-complete, jumping around intelligence.
2:28 Again, just like before, we've got our video views and we've got our video templates like search play and show category, okay?
2:35 We have our static content, that's gonna be a big topic of conversation in this section and this course.
2:43 And then we have a bunch of database stuff down here, things that mostly are just leave them alone, put them back there.
2:51 So for example, if we go to services, and we go to video service, like here's how you might do a query to get all of the videos,
3:00 or here's how you do a query using SQL model to get all the categories. All right, and here is the quote database, the video collector DB,
3:11 that is the SQLite data model backed by, are fronted by, I guess, by SQL model. And yeah, that's pretty much it. If you understand those pieces,
3:22 you know how to find your way around, right? So the views are over here. They all have methods and those folders
3:31 and those methods help you locate, basically, your way through the rest of the application.