Hello, friends, in this video, we shall see how we can build the you are dynamically in our last
application
for this purpose.
The Flask API contains a function called as you are called for.
It is a very useful function to construct the you are in a dynamic fashion.
This function accepts certain arguments.
One is the function for which you want to find out the you are ill and the other is a number of key
words.
One or more than one keyword arguments may be provided to it.
So it accepts the name of the function as the first argument, which is mandatory or compulsory.
And if it is needed, then certain keyword arguments may be provided, which may be used to form the
you are in dynamically.
It allows you to change the you are ill at one in one go without having to remember that you are.
Otherwise you will not remember there that you are in here by just using the keyword arguments.
You can form the you are in a dynamic manner.
Another advantage of this you are in for the function is that you will be able to handle the escaping
of some special characters, especially special characters with unique data.
Very transparently can be.
It can be done very transparently so that you don't have to.
You don't have to as a developer, you don't have to deal with those Unicode characters.
And another advantage of you are for function is that if your application is placed outside the outside
of the root you are, then you are in function, will automatically do it for you.
So all these are some of the advantages of this.
You are in function.
What we shall do.
We shall write a small python script in which you are in for a function is used and let us see how the
behaviour, our our output of the program is seen in front of us.
So let us demonstrate the example in front of you.
In this example, we shall see how to build the you are dynamically using the function called you are
for which is defined in the flask model.
You also need a function called redirect, the purpose of the redirect function is to redirect the browser
from one you are ill to the other.
You are one of the things that you are still to be.
Redirected to ease, to be first from our first using the you are for function.
So coming back to this court, what do we have in this program?
First, of course, is this is the last application object that you have to create.
Then we have to find a you are called a slash admin, and this you are is bound to.
A view function Collette's Hello, Ermin.
So if after the server is, you know, running, you give the URL as localhost 5000 slash admin, then
on the browser you should get this message.
Hello, admin.
This is a fairly simple.
Definition of if you are ill with the help of the root decorate.
Similarly, there is another are, which is defined as guest, but in front of it there is a variable
which is mentioned in the angler records.
So as a result, what will happen if you.
You the you are as local, almost 5000 guessed slash some other strings, let us say, and we're.
So that Envir will be.
Picked up as the value of this variable, which is mentioned in the angular brackets here, the name
of the variable is guessed and that it will be passed as a keyword arguments to the.
My view view function head August.
So when this halo function hello, guest function is executer.
On your brother, you should get a message.
Hello.
This is a placeholder percent as the value of this variable will be substituted here.
So hello.
And we'll as guest will be our.
Expected of.
Now, this is the straightforward way of.
Calling a review function which is associated with the you.
Now, what we are doing is we will be dynamically fetching the you are all associated with either Hello
Ermin or hello, your guest, depending on what is the value of the name variable, which is mentioned
in the third.
You are.
So we have a third.
You are mentioned are defined.
In this program, slash user slash name.
In the browser, suppose?
If the other one is local, lost 5000 users admin.
OK, so the admin will be the value of this variable name that will be given to the map review function
hello user.
So the real value of the name will be admin.
So this statement will be true.
So therefore, this part will be executed.
What does it do?
It will feature the you are for hello admin function.
Which, incidentally, is this and the map function is this, so therefore, hello, admin will be printed.
But if, on the other hand, the knees localhost 5000 slash, you slash anvil, so the name variable
will become will the argument to the Halo user function will become will.
This condition will not be true.
So the aspart will be executed.
What does it do?
It features that you are in for Hello Guest.
An additional parameter to this hello, you you are Alvar function is another attribute guest is equal
to name, in which case this is the real.
So what happens, the associated the wall becomes this one to be the director you are will be this.
And the associated function is, again, they saw the value of guest will be provided to this, your
argument you will get hello?
And we'll ask guests, so essentially what you are doing, you are selecting the you are dynamically
with the help of the you for function.
So this is the.
You know, explanation of this call of this flask application, what we will do.
We will execute this program.
The server will start and then we will open a browser, give the Eurail, according to this.
And then see that in first place, the Hello Amen will be displayed and then the execution of the hello
guest function will be performed.
So let us see through the Python script in which this entire program is written, is sealed as you are
building.
Not why I have executed that program.
The server is running now.
We will go to the browser and give the URL slash localhost 5000 slash.
First, we shall see whether he just by mentioning admin, the result admin and.
The Hello and Viola's guest.
These outputs will come and then we'll see how the.
Dynamic selection of fuel and redirection of the browser to the corresponding function takes place.
So I open the browser and there you are, localhost 5000 admin, as you expected.
Hello, admin will be printed.
Then I assume you are as hello.
Gerst.
M.V..
So this will become the variable part of the you are you want to the guest function and the output will
be healthy and will as guest.
This is also as for the expected lines.
Now comes the part of the.
Dynamic formation of you all.
So if I have to.
Do that.
And then I write user admin, so this becomes the variable part will be picked up by the associated
review function hello user admin name is equal to admin condition is true.
So therefore, the.
Hello.
Admin output will be displayed as a result of the redirection towards the function associated with the
tissue audit.
OK, and then again.
I will do another.
You are redirection by saying user M.V. allow the condition will not be true, so the expert will be
executed so it will be redirected towards the hello guest function.
That's it.
So there you see, the use of your will for function allows you to form the you are dynamically and
the.
Browser can be redirected towards any selected.
View function.