Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Jinja2 templates
Lecture: Project structure with shared layout

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this last section we talked a bit about organizing our templates folder and grouping those by where their related views lived.
0:09 We're not quite far enough along in our creation of our site to really see that manifest. So let me show you. Let me walk you through
0:16 what this is going to look like at the end so you can appreciate it a little bit better. Over here is what our site's going to look like at the end.
0:24 Notice we have our views folder. This is where our HTML view methods live. So in the account when we have stuff to do with account and home
0:34 we have like the home and about and packages. It'll be like details and popular and so on. We're going to organize all of our related templates
0:41 by their view that they come from. So over here we're going to say all the stuff to do with packages is going to be in a sub-folder called packages.
0:48 So we have two views that require HTML. Change it to templates inside the packages views. One's called details and one's called popular.
0:56 Those are the names of the methods. So it really helps us understand where those go. And most of them are going to use this shared layout.
1:04 So we also created a shared folder and we gave the file name a underscore at the beginning to say, "This is not meant to be used directly."
1:10 Now it's supposed to be consumed by all the other ones. So again, our site's really simple. You might not need this yet
1:18 but when you have fifty or a hundred templates and many many view files and what-not it's really confusing to know
1:24 "I want to change this page real quick, how do I get to it?" This will make it so much easier. So I definitely encourage you to
1:30 organize your stuff this way. But you know, not required by Flask more suggested by Michael.


Talk Python's Mastodon Michael Kennedy's Mastodon