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 is changing our project structure a little bit for these shared layouts. And you saw just a hint of that
0:08
in our example previously. As our application grows we're going to want to add more and more structure for what we're doing.
0:17
Here's a richer PyPI_webapp. This is really where we're going this is what we're going to come close to ending the course with.
0:26
Notice we have a controllers directory. This is where I move the views and I broke them into different files.
0:32
So the stuff related to accounting, or creating accounts is under account controller. This general homepage and stuff is under home
0:40
and then package related things like package details and so on it's in the the packages controller. Because each one of those controller modules
0:49
contains multiple views, it makes a lot of sense to create a sub folder in the templates page that maps to that controller.
0:58
So, for example, we're going to come over and say have an account folder in templates and put all the related views.
1:04
So when we say index, we don't have to say index_account and have them all mushed together. We also have one for home
1:10
and potentially one for packages and so on. Then we have the shared layout that we talked about. So shared underscore indicator as well.
1:18
So those two things they definitely don't try to request that directly. So most of the views are going to use the _layout. Not all of them.
1:28
For example maybe we want to add a site map and the site map will be generated by one of these page templates but obviously it's just going to be
1:35
an XML document. It doesn't make sense for it to use it but like 95% of the views will use this shared layout or some derivative thereof.