Hello, friends, in this video, we shall see what are the redirect or what is the redirect function
and what are the different airports that the flask application may encounter?
So the redirects and the errors.
The flask module has a function called redirect, the redirect function does exactly the same thing,
same thing what it redirects the user's browser to another target location.
Additionally, the reason the redirect function may be specified with a status call, what kind of status
the redirection may take was the prototype of redirect function is as you know, this is the syntax
of the redirect function.
Three parameters are needed.
What is the location means?
What the parameter is that you are in the new you are to which your application will be redirected that
you are.
The response should be redirected.
Second parameter is the status quo.
It this status quo is sent to the brothers here, the Ford is equal to three zero two.
I'll show you the different different status codes that it may take, the values of which can be used.
And the third parameter is the response parameter, which is used to create an object of the response
for the subsequent redirected location.
So these three parameters are provided to the redirect function.
The purpose is very obvious from one view function, the another response is created and the browser
or the web application will be redirected towards the other location.
That is the purpose of this redirect.
These are the standardized state of schools, three zero two is the default, and it will be generated
or that will be sent as an argument.
When the desire Eurail is found, other options are three zero zero.
Then there are multiple choices.
Three zero one is a status quo.
When the required rate is moved permanently, it is no more available.
Three zero three is rather not modified use proxy generally used by the status quo.
Three zero six it is for reserve and three zero seven is used when there is a temporary redirect.
So along with these status courts, most of most often use these three to do it is by default.
You know, if you do not mention it is always treasurable.
So such a redirect function.
I now use this related function to take the client's control, rather the server applications control
from one you are to the other.
You are all with the help of a redirect function that redirect use.
I would sure with the help of an example.
In this example, we shall see the use of redirect function, which is a part of the last module.
So all the requirements are to be imported first.
In addition to the flask of class.
The redirect function, you are ill for function, render rendered template function and request object,
these are all the requirements.
Then you start your.
Plus, application by setting up a flask application object.
Then in this script.
These three you are rules are defined by the rules, the character, the slash.
Which is.
Bound to the View Function Index.
It does nothing it renders a template called the login, that e-mail, which is a form in which the
user can enter the username.
So localhost Callon 5000 slash, if you will, there is this template will be displayed on your browser
providing you.
A textbook to enter the username and put it under the submit button, so this login, not e-mail submit
button will.
Take you to the hyperlinked login, so this is the second you are a rule that has been defined.
So if you come to this logging slash logging, you are all by using the post method, which is.
A part of the attribute of the form which is present in the logging that is also the matter that will
be used will be post so.
This will be true.
And if the request not form, that means the form in this log, in not e-mail.
In which there is a text box and the user has entered the user name as admin, then.
Slash logging route will be redirected towards another Eurail, which is the model for success.
So use the you are ill for function.
Success is the.
Metadata that has been defined.
What is the URL for that success?
So what will happen on your browser?
A message will be displayed as login successfully.
Right, but for example, let us say the user direct directly enters this.
You are in his brother localhost 5000 slash login, so that means what the matter is not post on the
other end, the method will be get the default method is remember the get method.
So this will not be executed.
The login function will execute this statement and the browser will be redirected towards the back to
the index you are in.
That means this one again, the login e-mail will be displayed for him to log in again.
So in the effect, what is happening?
This logged in successfully message will appear only if the user name has been given as admin to any
other user name, it will.
Larry, you know, reappear what will reappear, the login form will reappear, continue to reappear
till you give that username Asami.
OK, so this is the.
Example of redirect, let us see how it goes.
So the Python script for this exercise is named as related, not what started.
Will start.
Go to the browser and.
It is you are a local lost fighter slash.
So you are on the browser localhost 5000 is the URL, given that the Xbox.
This is the largest crowd estimate that will be rendered by using the intertemporal function.
Now, I will show both those situations or scenarios are possibilities.
One is I give you a username, something like this.
What is going to happen, this submit button will take you to the Log-in you are in.
Along with the metal attribute equal to post.
So the if condition will fail, even though the metal is post, the username is not admin, so this
is bound to reappear again.
OK, now, in the second situation or second case, I give the.
Your name is Ahmed again, if I.
Press log-in.
You will be redirected towards the new wall along with the.
Metal post, so the border conditions are through metal exposed username is Erdmann, so it will now
be redirected toward the success Eurail.
The message that will be displayed will be logged in successfully.
On the other night, I said, if I were directly you.
Slash Log-in.
What is going to happen that you will be redirected towards the logging, you are ill, but the metal
will not be pushed, so therefore.
The luggage will reappear, so all the three possibilities I will demonstrate here with the help of
the redirect function will come back just as the redirection feature is present in a flask application.
The flask also has a board function.
This abort function enables an early exit of the application and while exiting it can.
You know, emit a certain airport, it will accept the application with a certain error code, the use
is very simple abort.
It will take only one parameter, which is the error call.
These are different airports that are frequently used for zero.
Zero is a bad request.
That means when you are trying to access a U-Haul, which is not present, unauthenticated when the
user with a certain set of privileges is not allowed to access a particular location, then four zero
one will be the airport forbidden or zero one four zero four is a very commonly encountered airport.
When the required resources is not not found at all, four zero four four zero four six is not acceptable
for one.
Five is unsupported media type and unfortunately there are too many requests.
So I just listed out a few of those airports that your application may encounter when the application
is required to have an early exit out of that application.
So a small example is there which will show up and the use of the abort function that I will show with
the help of a very small example here in this example, the use of abort function, which is a part
of the last module that is being demonstrated here.
So in addition to the other resources to import the abort function from the last module, this is,
of course, the initialization of the application object.
The.
The court here is more or less similar to what we used as a as an example of a redirect function here.
Also, there is an index rule.
The backslash rule is.
Attached to the new function index, which in turn will render a template called Log-in Dot Estevan,
which login that e-mail, as you know, the login e-mail has a simple form with a text box and a button.
The user is asked to enter a username that's.
Right, but the in that estimate of the form in this log, in our e-mail will take you to the you are
logging.
The action attribute of this log into the e-mail form is.
Towards the logging slash logging ordeal, along with the metal to post.
OK, so when the user.
Click on the submit button, along with some data entered in the username, feel this you are and will
be accessed along with the post method.
So this condition will be the the associated new function will be executed in this function.
This condition is going to be true.
Now, inside with another, there is another condition.
If the form request, not form username, that means the text box in the login form inside that if you
have pressed your type of the admin as the name of the user or username, then second condition will
be true.
If this is true, the browser will be redirected towards the.
You function the you are for the you function success, this is that success you are in.
Associated with functioning success, what will be have what will be displayed and successfully will
be displayed when.
When the user enters the user name as admin.
If not.
Let me see if this condition is not true.
The matter, of course, is post, but the value entered in the user name is not admin.
So that means this else will be executed and.
Italy and Canada and Abbott function with the error call for zero one and four zero one is for unauthorized.
So on your browser, a message unauthorized will be displayed.
Right.
And, of course, as we saw in the last example, if the user directly enters logging in the Urals sorry,
the browser's address bar, then.
The matter is not so, therefore, this girls will be executed and it will again take you back to the
index where again the login page will be displayed, the form in which the username has to be entered.
OK, so importantly, we have to verify what happens as a result of this abort function for zero one,
is there a report that has been given?
So you should see the unauthorized.
Message being displayed on the browser if the username is not Al.
That will be the verification of the award function.
OK.
So the.
Transcript in which the abort function is used is called Abort Not Be, so I will start it so that the
server will start running.
Once it is running, we'll go to the browser.
Give the you are localhost 5000 slash.
The in that e-mail will be displayed.
Now, I will show you both those situations where the first place you enter the username has admin.
What happens, the logging, you will redirect your words, redirect you towards the success you are
handed, the message printed will be logged in successfully.
OK, so this is one Edvin.
He's a username, Log-in is successful again, go back to this.
Login page, now enter something else, something other than admin.
So I will say user.
If I click on it, it will redirect towards the logging, but is still post, but the username is not
admin, so therefore it will encounter the airport with four zero one airport.
So it will an unauthorized.
This is the message that comes along with that there's a different reasons why you may be unauthorized.
So that happens when.
Iraqi authorities, four zero 01.
And, of course, if you directly localhost by southern Log-in.
Then, of course, what will happen, it will again go back to the login form.
Like this.
So this demonstrates the use of board function in the flask.