Hello, friends, in this video, we shall see what are the static files in a flask application.
So in the last application so far, we have seen that there is a python code and then there is a template,
the template is essentially a civil war in which certain variable parties to be inserted with the help
of the ginger to template.
But as HTML, part of the webpage often requires the help of certain static files.
For instance, you may be requiring certain CSS or cascaded stylesheets you may be requiring or you
may require certain JavaScript which will be executing some client side functions.
So these static files are often required for the execution of a template.
So these static files are generally put into another special folder, just like the templates folder
to store the templates.
The static files are placed in a folder called static.
So you have to have a folder by the name Static in which either those yeses are dodgiest, such such
like files are put.
So this static folder must be provided inside the application in order to identify the location of these
static files.
A special endpoint called a static is used to generate the URL for those files.
So you are in for static, you are for static.
This is the folder in which the static files will be there.
For example, you are going to refer to a file called Styluses.
So the manner in which this you are in for a function that uses you are all for static.
The name of the folder.
By default it is static filename is equal to your file.
You want things that are distributed.
There are two application settings that you can use in order to configure your application.
One is AP not static.
You are in part.
Well, the static you are all parties by default, are part of the static folder, but you may choose
to put your static files in some some at somewhere else or in some different folder.
So in this case, you will find this spot.
Otherwise, by default, it defaults to the path of the static folder.
Similarly, under another configuration setting, also you can use FPP, not static folder.
Again, the default name of the static folder is static in the same application folder.
If it is different than you can mention it.
Static folder is something else.
So these are the two configuration settings which you rarely meet actually.
But then that is possible or available.
So what we will do, we will write a pattern called have a view function, make it render a template
and the template is going to use a static file called it in this in our example, it is used.
So let us see with the help of example how the static file is used.
So just as the.
The pledge to be rendered in a flask application are, you know, stored or put into a folder called
as templates.
Similarly, all the static files which are really needed for the execution of the webpages or templates,
for instance, there may be any JavaScript files or there may be any Gasconade stylesheet case files.
They will be stored in another special folder called a Static.
In which four in this example I am going to store, if I call that Hello Rajas.
So this Rogers is still in the static folder in your flask application.
So what is the purpose of this project, because in this project, I have defined a function policy
law which will be executed when.
I click this button, so there is a on the.
You know, homepage or Web page, and I'm just creating a button on click event of this button will
fire this Halo function, which is in the Halo Rogers.
So that I have to the world for this, I have to give to this script tibaijuka to text JavaScript SRT,
you must be aware of the syntax with which you define the.
Location of the JavaScript file in your webpage.
So what is the URL for this file?
Heterogenous.
A special endpoint called Static is used, and it's Eurail is operated by a well-known we already use
this function, you are informed, so you are ready for static.
It will obtain the you are for this static folder.
Another argument to this are for function is the filename is equal to this.
So whatever the you are in for this.
Hello Rogers will be faced by this.
You are all for function will be given the value of this SIRC parameter.
Uh, for script, script type is equal to the text of JavaScript.
OK, so this completes our.
Discussion of the template in this example.
OK.
Now, this is the this is the JavaScript file, which I am talking about, hello, Rogers has one function
defined.
Say hello.
All it is doing is when the function is executed, it will pop up a hello world, Mrs..
OK, so this is the Java script file, which is stored in the static folder in our flask application.
So this is my last application folder in which.
The template for that is there in which.
This index, not esteemable, is already there and there is a static folder in which this is installed.
OK, so the template and the JavaScript file are already available in your application.
Now we shall have a look at the python part of the entire called.
It is very simple.
All it is doing is defining you are Elul slash by the roof, decorated and associated.
Arbon function is index and it is doing nothing but rendering an index that is multiplied by the function
called render.
So what I am going to do, I start this hour of course, and then I'll give you.
Uh, the browser will be given the you are less localhost 5000 slash.
OK, so what will happen, the index function will be executed, a view function index will render the
index not estimate.
For this index indexer, internally, it is requiring the Rajas, which I have already mentioned.
By using the you are never static, OK, so let us see, one by one the activity started the server,
open the browser, give the you are in and see the result.
So the python called.
To define that.
You are all is present in the static dorber to render in index.
So I will execute that static dorper from the python prompt and start the server.
OK, so it is only now, starting now, we have to go to the browser and go to localhost.
Slash.
So the result of estimate will be rendered.
However, to say hello, that was.
There in the festival hall.
Now, if I click on this, the only event will call the say hello function, which is defined indeed.
Hello Rogers.
The URL for which is obtained by the you are an underscore for function.
And you should see this, Hallowell.
Alert message, which is generated by.
Uh, hello, gorgeous script.
OK, so all the static files are put in the folder static, which is which should be present in the
flask application.