Building Data-Driven Web Apps with Flask and SQLAlchemy Transcripts
Chapter: Jinja2 templates
Lecture: Better organization for your template files

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm not a huge fan of piling all your templates in here, no. It might seem like it's just no big deal it's all going to be fine because we have three
0:08 only two real ones and one is the shared one right? But if you look at something like we could have like 62 separate templates
0:18 and they under different circumstances look real similar like index. Now it could be the main index or it could be the index
0:24 for your account home or things like that. I really don't like having them all crammed in here. Let's do a little bit of work ahead of time
0:32 to get this organized better. Now there's not really enough going on here to make this super obvious. Still I think it will be, you'll get the idea.
0:39 So let's go here and make a directory called shared. You know what goes in shared? That's right, that goes in there.
0:46 And then we're going to make another one let's suppose we're going to have some home groupings stuff about the home page and what not
0:52 so like home about contact, those are all going to go in there. Now that seems pretty cool right? But there's going to be a load of problems.
1:04 How did that run? Did that get... Let's see if that got changed. Look at that! That is so incredible. Sometimes I forget PyCharm's just awesome.
1:15 So what happened when I dragged that in there is it said oh we were using this but now where you've moved it around
1:20 so in order to fix it so it doesn't crash 'cause it would have, it's going to put it put the directory name there.
1:26 So that's super cool that PyCharm fixed that and it also did that up here. Look at that when we put that in shared. So, okay, I'm impressed.
1:35 I was able to drag those all around and actually PyCharm fixed everything. But you would have to make sure that you did that.
1:42 Now let's just double-check one more time. Everything's still working. Home page, fancy fancy about page, all right.
1:49 It's all working just fine and it's using our nice new organization. You don't have to do this but trust me on real sites with 50 or 100 templates
1:59 you will thank yourself over and over again for this organization.

Talk Python's Mastodon Michael Kennedy's Mastodon