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
0:02
in here, no.
0:03
It might seem like it's just no big deal
0:05
it's all going to be fine because we have three
0:07
only two real ones and one is the shared one right?
0:10
But if you look at something like
0:11
training.talkpython.fm
0:13
we could have like 62 separate templates
0:17
and they under different circumstances
0:19
look real similar like index.
0:21
Now it could be the main index or it could be the index
0:23
for your account home or things like that.
0:26
I really don't like having them all crammed in here.
0:28
Let's do a little bit of work ahead of time
0:31
to get this organized better.
0:32
Now there's not really enough going on here
0:34
to make this super obvious.
0:36
Still I think it will be, you'll get the idea.
0:38
So let's go here and make a directory called shared.
0:41
You know what goes in shared?
0:42
That's right, that goes in there.
0:45
And then we're going to make another one
0:46
let's suppose we're going to have some home groupings
0:49
stuff about the home page and what not
0:51
so like home about contact, those are all going to go
0:55
in there. Now that seems pretty cool right?
0:57
But there's going to be a load of problems.
1:03
How did that run? Did that get...
1:06
Let's see if that got changed.
1:09
Look at that! That is so incredible.
1:12
Sometimes I forget PyCharm's just awesome.
1:14
So what happened when I dragged that in there
1:16
is it said oh we were using this
1:18
but now where you've moved it around
1:19
so in order to fix it so it doesn't crash
1:21
'cause it would have, it's going to put it
1:24
put the directory name there.
1:25
So that's super cool that PyCharm fixed that
1:27
and it also did that up here.
1:30
Look at that when we put that in shared.
1:32
So, okay, I'm impressed.
1:34
I was able to drag those all around
1:36
and actually PyCharm fixed everything.
1:38
But you would have to make sure that you did that.
1:41
Now let's just double-check one more time.
1:43
Everything's still working.
1:44
Home page, fancy fancy about page, all right.
1:48
It's all working just fine and it's using our nice
1:50
new organization.
1:53
You don't have to do this but trust me
1:54
on real sites with 50 or 100 templates
1:58
you will thank yourself over and over again
2:00
for this organization.