Building data-driven web apps with Pyramid and SQLAlchemy Transcripts
Chapter: Chameleon templates
Lecture: Project structure with layout

Login or purchase this course to watch this video and the rest of the course contents.
0:00 The final thing I want to look at
0:01 is changing our project structure
0:03 a little bit for these shared layouts.
0:05 And you saw just a hint of that
0:07 in our example previously.
0:10 As our application grows
0:12 we're going to want to add more and more structure
0:15 for what we're doing.
0:16 Here's a richer PyPI_webapp.
0:20 This is really where we're going
0:22 this is what we're going to come close
0:23 to ending the course with.
0:25 Notice we have a controllers directory.
0:28 This is where I move the views and I broke them
0:30 into different files.
0:31 So the stuff related to accounting, or creating accounts
0:34 is under account controller.
0:36 This general homepage and stuff is under home
0:39 and then package related things
0:41 like package details and so on
0:43 it's in the the packages controller.
0:45 Because each one of those controller modules
0:48 contains multiple views, it makes a lot of sense
0:51 to create a sub folder in the templates page
0:55 that maps to that controller.
0:57 So, for example, we're going to come over and say
1:00 have an account folder in templates
1:02 and put all the related views.
1:03 So when we say index, we don't have to say index_account
1:06 and have them all mushed together.
1:08 We also have one for home
1:09 and potentially one for packages and so on.
1:12 Then we have the shared layout that we talked about.
1:15 So shared underscore indicator as well.
1:17 So those two things they definitely
1:19 don't try to request that directly.
1:23 So most of the views are going to use the _layout.
1:26 Not all of them.
1:27 For example maybe we want to add a site map
1:29 and the site map will be generated by one of these
1:32 page templates but obviously it's just going to be
1:34 an XML document.
1:35 It doesn't make sense for it to use it
1:37 but like 95% of the views will use this shared layout
1:41 or some derivative thereof.