0% found this document useful (0 votes)
17 views2 pages

Extending HTML Templates - Transcript

The document discusses using templates in Flask to share common code between pages and reduce duplication. It describes creating a base.html template file with common HTML that both the index.html and about.html pages will extend. Index.html and about.html will each provide their own unique content by defining content blocks that will replace the main content block in base.html. This allows most of the code to be defined in a single place and customized on a per-page basis.

Uploaded by

bhuttoahmed2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Extending HTML Templates - Transcript

The document discusses using templates in Flask to share common code between pages and reduce duplication. It describes creating a base.html template file with common HTML that both the index.html and about.html pages will extend. Index.html and about.html will each provide their own unique content by defining content blocks that will replace the main content block in base.html. This allows most of the code to be defined in a single place and customized on a per-page basis.

Uploaded by

bhuttoahmed2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Welcome back.

So let's say you have the index fell.


But you also have something like in about Mitch
and let's create that round.
So after a drought, what would slash about Let's define
a function which will be executed when this out get
the request and we were done Another template in the same
about not S t m l.
So in next artist human, let's say we have ah, something
like Let's keep it really simple Actually, we have We have
a header deck and this is I go off Rip cyp when we have
another header which is sub hitter, something sleeping.
It's not important.
And let's say we have 100 on toe.
I am here and then we have some content.
Or maybe, ah, navigation menu.
So we have a list from page and another link of it says moat
bit. And finally, we have some content on the homepage.
Now let me duplicate this index start html.
So let me just copy all of this and in my templates folder
will create a fire call about S t. M A up with this
and shared all of this court except for this part
so some country, not the A boat, which that's the only
difference.
Really?
All right, So if I go back to our task manager now, I've
added the ah wrote for the about page as well.
So I have title of the website, some sub header and then just
a separate her line, um, home page about bitch.
I think I forgot to had at the links here.
Yeah, it's supposed to be.
You're not bread.
It's important.
But still, this is supposed to be home by AIDS
and the bridge, and I'll copy that, the other in next Stephen
file as well.
And this is the content on the home pit.
So let's try this again.
So I had this website now which has some sort of navigation,
some some better title, some content on the home page.
And if I go to about page and the food slash about, it's
exactly the same.
Except we have some contra number about bit.
And the point I'm trying to make is a lot of the scored is
actually just repeated, and there's no real reason to have
the holding in, uh, both the files.
So what we can do is share the scored using Ginger templates
and just keep the part, which is different
in these extremophiles.
So what I'll do is in our templates folder.
I'll create a new file and I'll call it Base brought Esteem.
Oh, and this will have basically all the court that we want
to share between all the other as table files.
So everything except for the last line here.
And instead of the last line, I will write curly brackets
and person person.
And this is how you can write a court block in ginger
templates.
So a red block and give it a name.
So this is my main content block, so I'll just call it mean
and then you need to close your content block, so you'll need
to again under the same thing.
So curly bracket person and percent curly bracket and rape
and block made this main name here is optional.
It'll automatically figure out which block you're talking
about so you can remove it if you want.
But I no, in the indexed artist email.
Uh, you don't need to have this here.
We will simply right.
We called junk, basically the court block, and it was
a expense and I couldn't code base, not esteem.
So we were simply extend based on breast UMA and insert
some content from this fire Do be based artist email fire
where it says block man.
So it's the block that we're going to right here and again.
The syntax is exactly the same.
You want to write block, I mean, and after you're done
with the content and you want to write and block, you save it
and you want to do the same thing for about a test email.
Except you know that content is a little different.
It says some content on the about Which Soviet extending
biggest artist Iemma and plugging this content.
This is demo whenever we have the main block, so I can just
to make it care venue.
Ah, vendor, index artist, human.
No, it will essentially load the based artist email file
and rendered that, and the only difference will be that it
will take the content off the me and block, which is
this line right here.
Plug it in in this part where it says mean block
in being started, human and then rendered that so save all
the files and Let's go back to our Firefox browser
and let's go to in Rex and even see we actually get the same
result as we did before, even of it.
The different factor in the sense that we're using a based
file now and re using some of the court from there.
And it's the same except for some content on the about bitch.
Great. So now you know how to use singer templates, and you
can also pass on a bunch of information.
Ah, to these templates, and you can actually use that in HTML
so you can dynamically change esteem, so we'll do all of that
in following tasks.
But before we get to that, that's also take a look at how
to use forms in flask.

You might also like