1 00:00:00,570 --> 00:00:08,400 Hello, friends, in this video, we shall see what are the redirect or what is the redirect function 2 00:00:08,410 --> 00:00:12,790 and what are the different airports that the flask application may encounter? 3 00:00:13,350 --> 00:00:16,050 So the redirects and the errors. 4 00:00:19,450 --> 00:00:26,690 The flask module has a function called redirect, the redirect function does exactly the same thing, 5 00:00:26,720 --> 00:00:36,270 same thing what it redirects the user's browser to another target location. 6 00:00:38,640 --> 00:00:48,570 Additionally, the reason the redirect function may be specified with a status call, what kind of status 7 00:00:48,720 --> 00:00:56,490 the redirection may take was the prototype of redirect function is as you know, this is the syntax 8 00:00:56,490 --> 00:00:58,950 of the redirect function. 9 00:00:59,850 --> 00:01:01,120 Three parameters are needed. 10 00:01:01,410 --> 00:01:04,080 What is the location means? 11 00:01:04,080 --> 00:01:12,240 What the parameter is that you are in the new you are to which your application will be redirected that 12 00:01:12,240 --> 00:01:12,590 you are. 13 00:01:13,020 --> 00:01:14,910 The response should be redirected. 14 00:01:16,110 --> 00:01:18,110 Second parameter is the status quo. 15 00:01:19,830 --> 00:01:25,810 It this status quo is sent to the brothers here, the Ford is equal to three zero two. 16 00:01:25,860 --> 00:01:32,580 I'll show you the different different status codes that it may take, the values of which can be used. 17 00:01:32,910 --> 00:01:39,630 And the third parameter is the response parameter, which is used to create an object of the response 18 00:01:39,630 --> 00:01:42,430 for the subsequent redirected location. 19 00:01:42,930 --> 00:01:47,330 So these three parameters are provided to the redirect function. 20 00:01:47,580 --> 00:01:57,250 The purpose is very obvious from one view function, the another response is created and the browser 21 00:01:57,250 --> 00:02:02,420 or the web application will be redirected towards the other location. 22 00:02:02,790 --> 00:02:04,740 That is the purpose of this redirect. 23 00:02:09,900 --> 00:02:20,160 These are the standardized state of schools, three zero two is the default, and it will be generated 24 00:02:20,160 --> 00:02:22,890 or that will be sent as an argument. 25 00:02:22,980 --> 00:02:30,420 When the desire Eurail is found, other options are three zero zero. 26 00:02:30,690 --> 00:02:32,250 Then there are multiple choices. 27 00:02:32,250 --> 00:02:34,370 Three zero one is a status quo. 28 00:02:34,410 --> 00:02:38,760 When the required rate is moved permanently, it is no more available. 29 00:02:39,090 --> 00:02:46,980 Three zero three is rather not modified use proxy generally used by the status quo. 30 00:02:47,130 --> 00:02:55,190 Three zero six it is for reserve and three zero seven is used when there is a temporary redirect. 31 00:02:55,710 --> 00:03:01,140 So along with these status courts, most of most often use these three to do it is by default. 32 00:03:01,140 --> 00:03:04,040 You know, if you do not mention it is always treasurable. 33 00:03:04,620 --> 00:03:06,690 So such a redirect function. 34 00:03:07,230 --> 00:03:15,270 I now use this related function to take the client's control, rather the server applications control 35 00:03:15,270 --> 00:03:17,430 from one you are to the other. 36 00:03:17,430 --> 00:03:21,510 You are all with the help of a redirect function that redirect use. 37 00:03:21,600 --> 00:03:23,970 I would sure with the help of an example. 38 00:03:25,080 --> 00:03:31,920 In this example, we shall see the use of redirect function, which is a part of the last module. 39 00:03:32,870 --> 00:03:36,470 So all the requirements are to be imported first. 40 00:03:37,490 --> 00:03:41,330 In addition to the flask of class. 41 00:03:42,470 --> 00:03:49,060 The redirect function, you are ill for function, render rendered template function and request object, 42 00:03:49,060 --> 00:03:51,010 these are all the requirements. 43 00:03:51,860 --> 00:03:53,360 Then you start your. 44 00:03:54,510 --> 00:03:58,710 Plus, application by setting up a flask application object. 45 00:04:00,640 --> 00:04:03,340 Then in this script. 46 00:04:04,420 --> 00:04:10,940 These three you are rules are defined by the rules, the character, the slash. 47 00:04:12,440 --> 00:04:13,160 Which is. 48 00:04:14,490 --> 00:04:17,550 Bound to the View Function Index. 49 00:04:19,790 --> 00:04:26,840 It does nothing it renders a template called the login, that e-mail, which is a form in which the 50 00:04:27,650 --> 00:04:29,330 user can enter the username. 51 00:04:30,850 --> 00:04:38,860 So localhost Callon 5000 slash, if you will, there is this template will be displayed on your browser 52 00:04:39,970 --> 00:04:40,780 providing you. 53 00:04:41,760 --> 00:04:49,200 A textbook to enter the username and put it under the submit button, so this login, not e-mail submit 54 00:04:49,200 --> 00:04:49,950 button will. 55 00:04:53,140 --> 00:04:58,450 Take you to the hyperlinked login, so this is the second you are a rule that has been defined. 56 00:05:01,900 --> 00:05:09,310 So if you come to this logging slash logging, you are all by using the post method, which is. 57 00:05:10,220 --> 00:05:16,460 A part of the attribute of the form which is present in the logging that is also the matter that will 58 00:05:16,460 --> 00:05:19,550 be used will be post so. 59 00:05:20,940 --> 00:05:21,870 This will be true. 60 00:05:23,320 --> 00:05:29,110 And if the request not form, that means the form in this log, in not e-mail. 61 00:05:30,440 --> 00:05:36,410 In which there is a text box and the user has entered the user name as admin, then. 62 00:05:39,770 --> 00:05:48,200 Slash logging route will be redirected towards another Eurail, which is the model for success. 63 00:05:48,260 --> 00:05:50,570 So use the you are ill for function. 64 00:05:50,900 --> 00:05:52,000 Success is the. 65 00:05:53,540 --> 00:05:54,860 Metadata that has been defined. 66 00:05:56,110 --> 00:05:58,320 What is the URL for that success? 67 00:05:59,920 --> 00:06:02,330 So what will happen on your browser? 68 00:06:02,350 --> 00:06:05,680 A message will be displayed as login successfully. 69 00:06:07,210 --> 00:06:12,720 Right, but for example, let us say the user direct directly enters this. 70 00:06:13,830 --> 00:06:20,640 You are in his brother localhost 5000 slash login, so that means what the matter is not post on the 71 00:06:20,640 --> 00:06:24,170 other end, the method will be get the default method is remember the get method. 72 00:06:24,540 --> 00:06:26,930 So this will not be executed. 73 00:06:27,900 --> 00:06:36,210 The login function will execute this statement and the browser will be redirected towards the back to 74 00:06:36,210 --> 00:06:38,130 the index you are in. 75 00:06:38,310 --> 00:06:44,170 That means this one again, the login e-mail will be displayed for him to log in again. 76 00:06:44,460 --> 00:06:47,220 So in the effect, what is happening? 77 00:06:48,210 --> 00:06:55,620 This logged in successfully message will appear only if the user name has been given as admin to any 78 00:06:55,620 --> 00:06:56,880 other user name, it will. 79 00:06:58,080 --> 00:07:04,110 Larry, you know, reappear what will reappear, the login form will reappear, continue to reappear 80 00:07:04,110 --> 00:07:06,830 till you give that username Asami. 81 00:07:07,710 --> 00:07:08,820 OK, so this is the. 82 00:07:10,270 --> 00:07:14,310 Example of redirect, let us see how it goes. 83 00:07:17,610 --> 00:07:22,940 So the Python script for this exercise is named as related, not what started. 84 00:07:23,940 --> 00:07:24,510 Will start. 85 00:07:25,620 --> 00:07:26,820 Go to the browser and. 86 00:07:28,050 --> 00:07:30,650 It is you are a local lost fighter slash. 87 00:07:32,880 --> 00:07:38,340 So you are on the browser localhost 5000 is the URL, given that the Xbox. 88 00:07:39,770 --> 00:07:45,680 This is the largest crowd estimate that will be rendered by using the intertemporal function. 89 00:07:46,250 --> 00:07:50,690 Now, I will show both those situations or scenarios are possibilities. 90 00:07:50,960 --> 00:07:55,370 One is I give you a username, something like this. 91 00:07:56,530 --> 00:08:03,580 What is going to happen, this submit button will take you to the Log-in you are in. 92 00:08:05,400 --> 00:08:08,220 Along with the metal attribute equal to post. 93 00:08:10,060 --> 00:08:15,860 So the if condition will fail, even though the metal is post, the username is not admin, so this 94 00:08:15,860 --> 00:08:17,240 is bound to reappear again. 95 00:08:19,280 --> 00:08:23,960 OK, now, in the second situation or second case, I give the. 96 00:08:25,640 --> 00:08:28,010 Your name is Ahmed again, if I. 97 00:08:29,010 --> 00:08:29,790 Press log-in. 98 00:08:31,130 --> 00:08:35,330 You will be redirected towards the new wall along with the. 99 00:08:36,910 --> 00:08:44,200 Metal post, so the border conditions are through metal exposed username is Erdmann, so it will now 100 00:08:44,200 --> 00:08:46,320 be redirected toward the success Eurail. 101 00:08:46,360 --> 00:08:49,990 The message that will be displayed will be logged in successfully. 102 00:08:50,930 --> 00:08:53,930 On the other night, I said, if I were directly you. 103 00:08:56,150 --> 00:08:57,230 Slash Log-in. 104 00:08:59,920 --> 00:09:05,470 What is going to happen that you will be redirected towards the logging, you are ill, but the metal 105 00:09:05,470 --> 00:09:07,750 will not be pushed, so therefore. 106 00:09:09,110 --> 00:09:15,980 The luggage will reappear, so all the three possibilities I will demonstrate here with the help of 107 00:09:15,980 --> 00:09:24,970 the redirect function will come back just as the redirection feature is present in a flask application. 108 00:09:25,490 --> 00:09:29,450 The flask also has a board function. 109 00:09:30,710 --> 00:09:38,630 This abort function enables an early exit of the application and while exiting it can. 110 00:09:40,110 --> 00:09:50,180 You know, emit a certain airport, it will accept the application with a certain error code, the use 111 00:09:50,280 --> 00:09:53,040 is very simple abort. 112 00:09:53,880 --> 00:09:56,880 It will take only one parameter, which is the error call. 113 00:09:57,510 --> 00:10:01,650 These are different airports that are frequently used for zero. 114 00:10:01,650 --> 00:10:03,800 Zero is a bad request. 115 00:10:03,810 --> 00:10:11,940 That means when you are trying to access a U-Haul, which is not present, unauthenticated when the 116 00:10:11,940 --> 00:10:18,810 user with a certain set of privileges is not allowed to access a particular location, then four zero 117 00:10:18,810 --> 00:10:27,160 one will be the airport forbidden or zero one four zero four is a very commonly encountered airport. 118 00:10:27,180 --> 00:10:35,400 When the required resources is not not found at all, four zero four four zero four six is not acceptable 119 00:10:35,670 --> 00:10:36,120 for one. 120 00:10:36,120 --> 00:10:41,570 Five is unsupported media type and unfortunately there are too many requests. 121 00:10:41,820 --> 00:10:50,310 So I just listed out a few of those airports that your application may encounter when the application 122 00:10:50,310 --> 00:10:53,980 is required to have an early exit out of that application. 123 00:10:54,390 --> 00:11:02,110 So a small example is there which will show up and the use of the abort function that I will show with 124 00:11:02,110 --> 00:11:11,460 the help of a very small example here in this example, the use of abort function, which is a part 125 00:11:11,460 --> 00:11:15,750 of the last module that is being demonstrated here. 126 00:11:15,790 --> 00:11:26,820 So in addition to the other resources to import the abort function from the last module, this is, 127 00:11:26,820 --> 00:11:29,910 of course, the initialization of the application object. 128 00:11:32,060 --> 00:11:32,690 The. 129 00:11:35,140 --> 00:11:42,820 The court here is more or less similar to what we used as a as an example of a redirect function here. 130 00:11:42,850 --> 00:11:45,070 Also, there is an index rule. 131 00:11:47,070 --> 00:11:48,180 The backslash rule is. 132 00:11:50,070 --> 00:11:56,550 Attached to the new function index, which in turn will render a template called Log-in Dot Estevan, 133 00:11:56,550 --> 00:12:06,180 which login that e-mail, as you know, the login e-mail has a simple form with a text box and a button. 134 00:12:06,210 --> 00:12:08,780 The user is asked to enter a username that's. 135 00:12:11,370 --> 00:12:19,530 Right, but the in that estimate of the form in this log, in our e-mail will take you to the you are 136 00:12:20,190 --> 00:12:20,670 logging. 137 00:12:21,560 --> 00:12:25,610 The action attribute of this log into the e-mail form is. 138 00:12:26,590 --> 00:12:31,660 Towards the logging slash logging ordeal, along with the metal to post. 139 00:12:34,900 --> 00:12:38,290 OK, so when the user. 140 00:12:39,830 --> 00:12:46,670 Click on the submit button, along with some data entered in the username, feel this you are and will 141 00:12:46,670 --> 00:12:50,020 be accessed along with the post method. 142 00:12:50,360 --> 00:12:56,960 So this condition will be the the associated new function will be executed in this function. 143 00:12:57,530 --> 00:12:59,110 This condition is going to be true. 144 00:13:00,260 --> 00:13:03,470 Now, inside with another, there is another condition. 145 00:13:03,800 --> 00:13:14,720 If the form request, not form username, that means the text box in the login form inside that if you 146 00:13:14,720 --> 00:13:21,860 have pressed your type of the admin as the name of the user or username, then second condition will 147 00:13:21,860 --> 00:13:22,270 be true. 148 00:13:22,760 --> 00:13:27,650 If this is true, the browser will be redirected towards the. 149 00:13:28,870 --> 00:13:35,380 You function the you are for the you function success, this is that success you are in. 150 00:13:36,630 --> 00:13:42,600 Associated with functioning success, what will be have what will be displayed and successfully will 151 00:13:42,600 --> 00:13:44,100 be displayed when. 152 00:13:45,080 --> 00:13:48,620 When the user enters the user name as admin. 153 00:13:50,110 --> 00:13:50,740 If not. 154 00:13:51,890 --> 00:13:53,790 Let me see if this condition is not true. 155 00:13:54,590 --> 00:14:00,260 The matter, of course, is post, but the value entered in the user name is not admin. 156 00:14:00,260 --> 00:14:04,730 So that means this else will be executed and. 157 00:14:05,690 --> 00:14:12,160 Italy and Canada and Abbott function with the error call for zero one and four zero one is for unauthorized. 158 00:14:12,500 --> 00:14:17,090 So on your browser, a message unauthorized will be displayed. 159 00:14:19,370 --> 00:14:19,740 Right. 160 00:14:20,510 --> 00:14:29,490 And, of course, as we saw in the last example, if the user directly enters logging in the Urals sorry, 161 00:14:29,510 --> 00:14:32,300 the browser's address bar, then. 162 00:14:33,270 --> 00:14:38,310 The matter is not so, therefore, this girls will be executed and it will again take you back to the 163 00:14:38,310 --> 00:14:45,960 index where again the login page will be displayed, the form in which the username has to be entered. 164 00:14:47,150 --> 00:14:53,750 OK, so importantly, we have to verify what happens as a result of this abort function for zero one, 165 00:14:53,750 --> 00:14:55,250 is there a report that has been given? 166 00:14:55,460 --> 00:14:59,030 So you should see the unauthorized. 167 00:15:00,190 --> 00:15:04,150 Message being displayed on the browser if the username is not Al. 168 00:15:05,240 --> 00:15:07,870 That will be the verification of the award function. 169 00:15:08,880 --> 00:15:09,330 OK. 170 00:15:13,260 --> 00:15:13,980 So the. 171 00:15:15,390 --> 00:15:22,350 Transcript in which the abort function is used is called Abort Not Be, so I will start it so that the 172 00:15:22,350 --> 00:15:23,850 server will start running. 173 00:15:25,590 --> 00:15:28,680 Once it is running, we'll go to the browser. 174 00:15:30,630 --> 00:15:33,400 Give the you are localhost 5000 slash. 175 00:15:35,300 --> 00:15:37,760 The in that e-mail will be displayed. 176 00:15:39,510 --> 00:15:46,830 Now, I will show you both those situations where the first place you enter the username has admin. 177 00:15:48,410 --> 00:15:58,290 What happens, the logging, you will redirect your words, redirect you towards the success you are 178 00:15:58,460 --> 00:16:02,510 handed, the message printed will be logged in successfully. 179 00:16:03,690 --> 00:16:05,970 OK, so this is one Edvin. 180 00:16:07,010 --> 00:16:11,570 He's a username, Log-in is successful again, go back to this. 181 00:16:18,130 --> 00:16:24,650 Login page, now enter something else, something other than admin. 182 00:16:25,160 --> 00:16:26,620 So I will say user. 183 00:16:29,610 --> 00:16:37,500 If I click on it, it will redirect towards the logging, but is still post, but the username is not 184 00:16:37,500 --> 00:16:41,790 admin, so therefore it will encounter the airport with four zero one airport. 185 00:16:43,440 --> 00:16:45,270 So it will an unauthorized. 186 00:16:46,570 --> 00:16:52,890 This is the message that comes along with that there's a different reasons why you may be unauthorized. 187 00:16:53,660 --> 00:16:54,600 So that happens when. 188 00:16:56,120 --> 00:16:58,160 Iraqi authorities, four zero 01. 189 00:16:59,480 --> 00:17:05,450 And, of course, if you directly localhost by southern Log-in. 190 00:17:07,580 --> 00:17:14,210 Then, of course, what will happen, it will again go back to the login form. 191 00:17:16,010 --> 00:17:16,700 Like this. 192 00:17:17,610 --> 00:17:21,610 So this demonstrates the use of board function in the flask.