In this video, we shall see what are the templates as far as the flask application framework is concerned,
but in this exercise we shall see how to use the template in a flask application.
We have seen that.
Any of you function, which is, you know, mapped with a particular rule or a particular, you are
in the function returns the text in the rather the output in the form of a plain text.
So if you have written Hello, World, as we have written in the very first application, if you just
return Hello World, that were the text Hello world is rendered in the form of a plain text, but it
can be rendered in the form of an e-mail.
If the string to be rendered is manually composed in the form of an e-mail text, for example.
In the script, this is the You are el.
This is the you are a rule which is bound with.
This function called an index.
And inside this index function, I have constructed a.
Variable called the Star with the help of a triple coded string in which these e-mail tags are concatenated
to form a simple e-mail.
Hello, world, which is.
You know, put inside the H1 and and and slash actual tags so that Hello world is expected to be displayed
with the healing tag, that means it will be in a smaller format and this thing is now being returned
when this function is called.
So what do you expect after starting the service?
If I just say localhost 5000, call backslash, then this index page index function, rather, will
be, uh, executed.
And Hello World is expected to be printed with H1 tag that means in Boulder font.
So this is what we expect.
This is a symbol, the same exercise of hello world that we did in the beginning, but now it is in
the form of SGV.
So let us see.
So let me start the server by executing this hallowed out by.
The server is running.
No, I will just issue localhost Kolon 5000 slash, which will execute the index.
Function, which is mapped and it will display high level.
So this is a manual way of rendering e-mail to the browser via our view function.
So now instead of manually rendering the text in the e-mail form to the browser, we shall now put that
e-mail.
You know, script into an HTML page and.
Redirect our browser.
From the view function directly to that particular e-mail page, by using the render template function
in the flask in a module.
So for that purpose, first I have created a simple hello world web page and it has to be stored in
a templates folder in your.
Application full, that means what?
So this is going to be our e-mail.
As rather, the Python script, which we will eventually run to start our.
Serwer, This is the halo that were on the same level of which there must be a template for all this
is, of course, our virtual environment.
So at the sea, in the same direction in which this hollowed out power is there, create a folder called
as templates and in which you stored this.
Hello, David.
Right.
So this is what you need to do, know whenever you want to.
Fire a template from the flask view function, that e-mail.
Script must be present in this template folder.
Now coming back to this hallowed out by Python script.
You know, in order to render the template, you have to use a function called as rendered template
itself, which is present in the flask model.
So you have to imported from flask, import the flask.
Glass and function relatively.
So, like before this backslides, you are is bound to the index function now, instead of manually
rendering the e-mail code, I'll just say return a template, which is the template that you want to,
which is the e-mail that you want to render a LORADITCH will ensure that it is already present in the
templates folder.
So this is what you.
Should write in the hallowed out by the Python script, which you will use for starting your sutler.
So let us start the server by executing this alert by.
This is now running.
Go back to the browser now.
And.
And we the same moral localhost, 5000 backslash.
Again, the Hollowell will be printed, another difference is that this Hallowell is now not rendered
manually by creating a cascade or concatenate string, having extreme events, but rather there is a
esteemable page e-mail in the template folder and that is being rendered as a template.