1 00:00:00,840 --> 00:00:08,490 Hello, friends, in this video, we shall see how we can build the you are dynamically in our last 2 00:00:08,490 --> 00:00:09,030 application 3 00:00:12,810 --> 00:00:13,800 for this purpose. 4 00:00:14,100 --> 00:00:18,780 The Flask API contains a function called as you are called for. 5 00:00:19,800 --> 00:00:24,550 It is a very useful function to construct the you are in a dynamic fashion. 6 00:00:25,710 --> 00:00:30,060 This function accepts certain arguments. 7 00:00:30,690 --> 00:00:38,310 One is the function for which you want to find out the you are ill and the other is a number of key 8 00:00:38,320 --> 00:00:38,550 words. 9 00:00:39,120 --> 00:00:43,230 One or more than one keyword arguments may be provided to it. 10 00:00:43,980 --> 00:00:48,960 So it accepts the name of the function as the first argument, which is mandatory or compulsory. 11 00:00:49,230 --> 00:00:58,590 And if it is needed, then certain keyword arguments may be provided, which may be used to form the 12 00:00:59,100 --> 00:01:00,240 you are in dynamically. 13 00:01:01,980 --> 00:01:08,590 It allows you to change the you are ill at one in one go without having to remember that you are. 14 00:01:08,970 --> 00:01:15,300 Otherwise you will not remember there that you are in here by just using the keyword arguments. 15 00:01:15,300 --> 00:01:18,640 You can form the you are in a dynamic manner. 16 00:01:20,430 --> 00:01:26,850 Another advantage of this you are in for the function is that you will be able to handle the escaping 17 00:01:27,360 --> 00:01:34,320 of some special characters, especially special characters with unique data. 18 00:01:34,800 --> 00:01:36,360 Very transparently can be. 19 00:01:36,360 --> 00:01:40,550 It can be done very transparently so that you don't have to. 20 00:01:40,590 --> 00:01:46,250 You don't have to as a developer, you don't have to deal with those Unicode characters. 21 00:01:46,950 --> 00:01:57,300 And another advantage of you are for function is that if your application is placed outside the outside 22 00:01:57,300 --> 00:02:04,150 of the root you are, then you are in function, will automatically do it for you. 23 00:02:04,530 --> 00:02:09,120 So all these are some of the advantages of this. 24 00:02:09,120 --> 00:02:10,010 You are in function. 25 00:02:10,680 --> 00:02:11,520 What we shall do. 26 00:02:11,850 --> 00:02:18,450 We shall write a small python script in which you are in for a function is used and let us see how the 27 00:02:18,450 --> 00:02:22,380 behaviour, our our output of the program is seen in front of us. 28 00:02:22,380 --> 00:02:24,900 So let us demonstrate the example in front of you. 29 00:02:25,770 --> 00:02:34,860 In this example, we shall see how to build the you are dynamically using the function called you are 30 00:02:35,000 --> 00:02:38,220 for which is defined in the flask model. 31 00:02:39,120 --> 00:02:47,970 You also need a function called redirect, the purpose of the redirect function is to redirect the browser 32 00:02:47,970 --> 00:02:50,220 from one you are ill to the other. 33 00:02:50,250 --> 00:02:53,640 You are one of the things that you are still to be. 34 00:02:54,700 --> 00:03:02,260 Redirected to ease, to be first from our first using the you are for function. 35 00:03:03,250 --> 00:03:08,560 So coming back to this court, what do we have in this program? 36 00:03:09,280 --> 00:03:14,920 First, of course, is this is the last application object that you have to create. 37 00:03:15,920 --> 00:03:25,990 Then we have to find a you are called a slash admin, and this you are is bound to. 38 00:03:27,490 --> 00:03:29,500 A view function Collette's Hello, Ermin. 39 00:03:30,870 --> 00:03:41,850 So if after the server is, you know, running, you give the URL as localhost 5000 slash admin, then 40 00:03:42,630 --> 00:03:45,340 on the browser you should get this message. 41 00:03:45,480 --> 00:03:46,320 Hello, admin. 42 00:03:47,200 --> 00:03:48,630 This is a fairly simple. 43 00:03:49,690 --> 00:03:53,850 Definition of if you are ill with the help of the root decorate. 44 00:03:55,750 --> 00:04:02,470 Similarly, there is another are, which is defined as guest, but in front of it there is a variable 45 00:04:02,830 --> 00:04:05,670 which is mentioned in the angler records. 46 00:04:06,370 --> 00:04:09,070 So as a result, what will happen if you. 47 00:04:10,150 --> 00:04:18,550 You the you are as local, almost 5000 guessed slash some other strings, let us say, and we're. 48 00:04:19,820 --> 00:04:21,590 So that Envir will be. 49 00:04:23,220 --> 00:04:29,850 Picked up as the value of this variable, which is mentioned in the angular brackets here, the name 50 00:04:29,850 --> 00:04:36,270 of the variable is guessed and that it will be passed as a keyword arguments to the. 51 00:04:37,870 --> 00:04:40,990 My view view function head August. 52 00:04:41,960 --> 00:04:45,170 So when this halo function hello, guest function is executer. 53 00:04:46,280 --> 00:04:48,150 On your brother, you should get a message. 54 00:04:48,240 --> 00:04:48,620 Hello. 55 00:04:49,920 --> 00:04:55,330 This is a placeholder percent as the value of this variable will be substituted here. 56 00:04:55,620 --> 00:04:56,360 So hello. 57 00:04:56,640 --> 00:04:59,220 And we'll as guest will be our. 58 00:05:00,700 --> 00:05:01,450 Expected of. 59 00:05:02,570 --> 00:05:05,000 Now, this is the straightforward way of. 60 00:05:06,030 --> 00:05:11,040 Calling a review function which is associated with the you. 61 00:05:12,120 --> 00:05:19,410 Now, what we are doing is we will be dynamically fetching the you are all associated with either Hello 62 00:05:19,410 --> 00:05:29,520 Ermin or hello, your guest, depending on what is the value of the name variable, which is mentioned 63 00:05:29,520 --> 00:05:30,490 in the third. 64 00:05:30,510 --> 00:05:30,870 You are. 65 00:05:31,110 --> 00:05:32,040 So we have a third. 66 00:05:32,040 --> 00:05:33,840 You are mentioned are defined. 67 00:05:35,330 --> 00:05:38,600 In this program, slash user slash name. 68 00:05:42,450 --> 00:05:44,150 In the browser, suppose? 69 00:05:45,580 --> 00:05:51,370 If the other one is local, lost 5000 users admin. 70 00:05:53,270 --> 00:05:59,830 OK, so the admin will be the value of this variable name that will be given to the map review function 71 00:05:59,960 --> 00:06:00,850 hello user. 72 00:06:01,640 --> 00:06:03,890 So the real value of the name will be admin. 73 00:06:04,070 --> 00:06:05,900 So this statement will be true. 74 00:06:07,170 --> 00:06:09,900 So therefore, this part will be executed. 75 00:06:10,140 --> 00:06:10,890 What does it do? 76 00:06:11,220 --> 00:06:14,550 It will feature the you are for hello admin function. 77 00:06:15,820 --> 00:06:22,300 Which, incidentally, is this and the map function is this, so therefore, hello, admin will be printed. 78 00:06:24,030 --> 00:06:32,820 But if, on the other hand, the knees localhost 5000 slash, you slash anvil, so the name variable 79 00:06:32,820 --> 00:06:39,770 will become will the argument to the Halo user function will become will. 80 00:06:39,960 --> 00:06:41,360 This condition will not be true. 81 00:06:41,640 --> 00:06:43,410 So the aspart will be executed. 82 00:06:43,980 --> 00:06:44,640 What does it do? 83 00:06:44,970 --> 00:06:48,000 It features that you are in for Hello Guest. 84 00:06:49,630 --> 00:06:56,230 An additional parameter to this hello, you you are Alvar function is another attribute guest is equal 85 00:06:56,230 --> 00:06:58,030 to name, in which case this is the real. 86 00:06:58,970 --> 00:07:06,230 So what happens, the associated the wall becomes this one to be the director you are will be this. 87 00:07:07,440 --> 00:07:14,940 And the associated function is, again, they saw the value of guest will be provided to this, your 88 00:07:15,030 --> 00:07:16,770 argument you will get hello? 89 00:07:17,850 --> 00:07:26,370 And we'll ask guests, so essentially what you are doing, you are selecting the you are dynamically 90 00:07:26,370 --> 00:07:28,860 with the help of the you for function. 91 00:07:29,690 --> 00:07:30,440 So this is the. 92 00:07:31,520 --> 00:07:37,790 You know, explanation of this call of this flask application, what we will do. 93 00:07:39,150 --> 00:07:41,550 We will execute this program. 94 00:07:42,550 --> 00:07:50,620 The server will start and then we will open a browser, give the Eurail, according to this. 95 00:07:51,610 --> 00:08:00,550 And then see that in first place, the Hello Amen will be displayed and then the execution of the hello 96 00:08:00,550 --> 00:08:02,820 guest function will be performed. 97 00:08:03,100 --> 00:08:09,550 So let us see through the Python script in which this entire program is written, is sealed as you are 98 00:08:09,580 --> 00:08:09,980 building. 99 00:08:09,980 --> 00:08:13,480 Not why I have executed that program. 100 00:08:13,490 --> 00:08:15,360 The server is running now. 101 00:08:15,370 --> 00:08:21,810 We will go to the browser and give the URL slash localhost 5000 slash. 102 00:08:23,100 --> 00:08:28,800 First, we shall see whether he just by mentioning admin, the result admin and. 103 00:08:29,960 --> 00:08:32,150 The Hello and Viola's guest. 104 00:08:33,430 --> 00:08:36,160 These outputs will come and then we'll see how the. 105 00:08:37,170 --> 00:08:43,650 Dynamic selection of fuel and redirection of the browser to the corresponding function takes place. 106 00:08:47,090 --> 00:08:53,060 So I open the browser and there you are, localhost 5000 admin, as you expected. 107 00:08:53,300 --> 00:08:54,860 Hello, admin will be printed. 108 00:08:56,370 --> 00:08:59,310 Then I assume you are as hello. 109 00:09:02,640 --> 00:09:03,300 Gerst. 110 00:09:04,700 --> 00:09:05,120 M.V.. 111 00:09:06,230 --> 00:09:14,540 So this will become the variable part of the you are you want to the guest function and the output will 112 00:09:14,540 --> 00:09:16,480 be healthy and will as guest. 113 00:09:16,520 --> 00:09:19,190 This is also as for the expected lines. 114 00:09:19,820 --> 00:09:21,740 Now comes the part of the. 115 00:09:23,920 --> 00:09:27,410 Dynamic formation of you all. 116 00:09:27,640 --> 00:09:28,720 So if I have to. 117 00:09:30,100 --> 00:09:30,730 Do that. 118 00:09:32,540 --> 00:09:42,080 And then I write user admin, so this becomes the variable part will be picked up by the associated 119 00:09:42,080 --> 00:09:47,310 review function hello user admin name is equal to admin condition is true. 120 00:09:47,510 --> 00:09:48,410 So therefore, the. 121 00:09:50,020 --> 00:09:50,530 Hello. 122 00:09:51,630 --> 00:10:02,070 Admin output will be displayed as a result of the redirection towards the function associated with the 123 00:10:02,590 --> 00:10:03,330 tissue audit. 124 00:10:05,120 --> 00:10:07,310 OK, and then again. 125 00:10:10,040 --> 00:10:11,180 I will do another. 126 00:10:12,310 --> 00:10:20,230 You are redirection by saying user M.V. allow the condition will not be true, so the expert will be 127 00:10:20,230 --> 00:10:25,020 executed so it will be redirected towards the hello guest function. 128 00:10:26,530 --> 00:10:27,030 That's it. 129 00:10:27,970 --> 00:10:35,070 So there you see, the use of your will for function allows you to form the you are dynamically and 130 00:10:35,070 --> 00:10:35,320 the. 131 00:10:36,510 --> 00:10:41,430 Browser can be redirected towards any selected. 132 00:10:42,640 --> 00:10:43,390 View function.