1 00:00:00,540 --> 00:00:09,540 Hello, friends, in this video, we shall see the form a tribute of the request object in a flask application. 2 00:00:14,040 --> 00:00:24,990 When the e-mail form is posted or when inside the e-mail form, you give the different form, attributes 3 00:00:26,190 --> 00:00:30,560 like matter is equal to is one attribute and action is equal to another attribute. 4 00:00:31,200 --> 00:00:41,010 For instance, have a look at this line of the e-mail form from action is equal to this is where the 5 00:00:41,010 --> 00:00:47,610 data is to be directed or said this is where you are and to which it is to be said and which is the 6 00:00:47,610 --> 00:00:53,010 method to use the method to be used is written as that would of method is equal to in this case it is 7 00:00:53,010 --> 00:00:54,320 being used as post. 8 00:00:54,990 --> 00:00:59,940 So this is the beginning of the formal declaration and this is the end of the formal declaration form 9 00:01:00,960 --> 00:01:01,800 between which. 10 00:01:03,180 --> 00:01:04,920 Different form elements are used. 11 00:01:05,910 --> 00:01:12,930 In this case, the former elements are nothing but just for text elements, are there input Irish politics 12 00:01:12,930 --> 00:01:13,460 four times? 13 00:01:13,500 --> 00:01:22,260 Do you see that they are being written in the name of the former element, is written by name, is equal 14 00:01:22,260 --> 00:01:22,890 to attribute. 15 00:01:23,160 --> 00:01:24,840 So name is the label. 16 00:01:25,290 --> 00:01:29,600 Input to the text name is called the name. 17 00:01:29,610 --> 00:01:34,510 This name is what the name of the family name is called Physics Chemistry. 18 00:01:34,700 --> 00:01:41,760 And so therefore when this e-mail page is open, what will be rendered on the client browser, it will 19 00:01:41,760 --> 00:01:49,530 just have a form of it for next week's each having a label like name, physics, chemistry, mathematics 20 00:01:49,530 --> 00:01:49,980 like this. 21 00:01:50,250 --> 00:01:56,550 And then at the end of that, the form there is a submit button so that when the submit button is clicked, 22 00:01:56,940 --> 00:02:00,750 the form the will be redirected towards this. 23 00:02:00,750 --> 00:02:01,290 You are it. 24 00:02:02,820 --> 00:02:08,640 What is this you are which going to localhost five thousand with the two words that you are, it will 25 00:02:08,640 --> 00:02:12,090 be redirected to use this post. 26 00:02:12,790 --> 00:02:22,770 OK, so in order to process this data, what I would do, I have to define this URL and map that you 27 00:02:22,770 --> 00:02:27,750 are all with a certain view function and that function will process the form data. 28 00:02:28,860 --> 00:02:29,280 How. 29 00:02:32,040 --> 00:02:42,170 Like this, this is the pattern you are defined as a result because that is where the data is coming 30 00:02:42,630 --> 00:02:43,730 and the map of the function. 31 00:02:45,630 --> 00:02:50,280 If the request documentary is equal to post, then what has to be done? 32 00:02:51,270 --> 00:02:58,990 The data collected, which is where it is collected, it is collected in that we would call that request 33 00:02:58,990 --> 00:02:59,520 not form. 34 00:03:00,060 --> 00:03:03,390 That result is stored in addition to the object called a result. 35 00:03:04,470 --> 00:03:09,870 And that dictionary object is used as a barometer to this render template function. 36 00:03:10,470 --> 00:03:14,880 So this render template function will render this table that estimate and. 37 00:03:16,370 --> 00:03:25,760 It will take up the reserve parameter, and that is barometer out process, that result parameter inside 38 00:03:25,760 --> 00:03:28,850 the template code off, they will not estimate. 39 00:03:29,570 --> 00:03:37,850 OK, so third parties, this template, remember that this table, that esteemable, should be stored 40 00:03:37,850 --> 00:03:39,710 in a template for them. 41 00:03:40,190 --> 00:03:44,690 So in that template folder, this table or the estimate, is that what it is doing? 42 00:03:45,140 --> 00:03:54,620 It is just iterating over the result object with the help of IT writeups functions, it will form an 43 00:03:54,620 --> 00:03:57,670 iterator over the dictionary object. 44 00:03:58,340 --> 00:04:04,210 You know that the dictionary object is a collection of items and each item is having a key and value. 45 00:04:05,480 --> 00:04:09,950 So for each key and value for this, it is starting a table. 46 00:04:12,600 --> 00:04:19,770 And for each value of these key and value, those key and value of first items, second, third and 47 00:04:19,770 --> 00:04:23,800 so on, all these items will be placed in a room. 48 00:04:24,030 --> 00:04:30,960 So at the end, what you should see, you should see the table XHTML table being rendered on the client 49 00:04:30,960 --> 00:04:38,220 browser with all those four parameters name physics, chemistry, mathematics and values such like they 50 00:04:38,260 --> 00:04:40,950 will be generated when you execute this. 51 00:04:41,610 --> 00:04:44,850 So what we have we have all these three components. 52 00:04:45,330 --> 00:04:50,090 One is the form estimate form second and the third is the template. 53 00:04:50,430 --> 00:04:53,910 So I'll show you these three ingredients of the code. 54 00:04:54,930 --> 00:04:57,630 Put it on at one in one application folder. 55 00:04:57,960 --> 00:04:59,880 Execute this Python script. 56 00:05:00,990 --> 00:05:07,350 The server will run in, fill the data in the form and see that the table is generated. 57 00:05:07,530 --> 00:05:13,860 All this we will see with the help of a practical example in front of, you know, using this example, 58 00:05:14,700 --> 00:05:26,360 we shall now see how to send an e-mail form data to a particular you are, which is defined by the root 59 00:05:26,430 --> 00:05:28,380 decorator in your application. 60 00:05:29,530 --> 00:05:38,200 So to start with, you have to import all the required, you know, functions and classes. 61 00:05:39,210 --> 00:05:41,400 As usual, you needed. 62 00:05:42,360 --> 00:05:44,160 Import the flask plus. 63 00:05:45,210 --> 00:05:47,610 Because you want to render the template. 64 00:05:49,300 --> 00:05:53,990 The render template function and also import the request object. 65 00:05:55,910 --> 00:06:01,790 OK, so this Python script actually has two rules, which are different. 66 00:06:02,150 --> 00:06:04,670 One is this backslash you are in. 67 00:06:05,640 --> 00:06:08,820 And the other is the result, you are Elwick. 68 00:06:11,400 --> 00:06:18,900 The root function root matter, rather, while dividing these slightly children, also takes one more 69 00:06:18,900 --> 00:06:25,320 argument, which is the methods, argument and methods have been or any of these two methods, subject 70 00:06:25,320 --> 00:06:31,920 matter can be, uh, you know, applicable or acceptable to this particular. 71 00:06:32,950 --> 00:06:33,850 It is Arturo. 72 00:06:34,950 --> 00:06:35,910 Of which we are. 73 00:06:37,560 --> 00:06:41,880 Basically interested in what happens if the metal is pushed so that. 74 00:06:43,690 --> 00:06:51,730 Afterwards, initially, when the server starts and you gather you are in your browser like localhost 75 00:06:51,730 --> 00:07:00,310 5000, slash the bone function here is in this case to run this interview function and then this function 76 00:07:00,310 --> 00:07:01,180 is executed. 77 00:07:04,170 --> 00:07:11,940 A student or e-mail template, which obviously must be present in the templates folder of your application, 78 00:07:12,210 --> 00:07:15,030 will be rendered, what is this student body? 79 00:07:16,050 --> 00:07:23,460 It is a simple form in which some data can be entered that we shall have a look at it afterwards. 80 00:07:24,700 --> 00:07:32,710 Right, so start the server unit slash backslash, you are in this template, will you render it will 81 00:07:32,710 --> 00:07:36,940 generate a form so the user will now enter the form. 82 00:07:37,860 --> 00:07:41,640 So at this juncture, shall we see what is the form? 83 00:07:44,930 --> 00:07:54,850 This is a simple form in which three text inputs are, you know, the reader input type you can to text 84 00:07:54,850 --> 00:07:56,080 that, read the text box. 85 00:07:57,300 --> 00:08:02,700 Three, not three or four, rather, one text box or name, physics, chemistry and mathematics, and 86 00:08:03,270 --> 00:08:05,700 and then there are of course, there is a submit button. 87 00:08:06,420 --> 00:08:08,130 So importantly, this all. 88 00:08:09,230 --> 00:08:13,610 Input types are present in the form whose action? 89 00:08:14,810 --> 00:08:21,770 Attribute is directed towards a you are in local fighters desert. 90 00:08:23,490 --> 00:08:24,930 And the is pushed. 91 00:08:25,960 --> 00:08:33,100 So this is as simple as you will see, a very simple, stable form that was created and this student 92 00:08:33,140 --> 00:08:36,250 body is put into the templates folder. 93 00:08:38,940 --> 00:08:41,130 Now, coming back to this Python script. 94 00:08:42,250 --> 00:08:48,220 This is the result you are in, which is used as the action attribute of the former. 95 00:08:49,400 --> 00:08:55,370 So what what what does it mean when you click on the submit button, the form will be posted to this 96 00:08:55,580 --> 00:09:03,380 desert slash result, you are ill and since the scenes in those days will call you the mythological 97 00:09:03,470 --> 00:09:03,890 post. 98 00:09:05,510 --> 00:09:08,400 So the data will be received by this result. 99 00:09:09,050 --> 00:09:15,020 You are in the post ometer, so the associated function you function is. 100 00:09:15,360 --> 00:09:18,500 This will be executer this statement is true. 101 00:09:18,500 --> 00:09:21,250 Requestor method is equal to post. 102 00:09:21,260 --> 00:09:22,460 So therefore, what will happen? 103 00:09:22,940 --> 00:09:27,320 It will fetch the entire data from the. 104 00:09:28,980 --> 00:09:29,520 From. 105 00:09:31,410 --> 00:09:33,720 Using the request not from. 106 00:09:35,850 --> 00:09:36,360 Mr.. 107 00:09:37,670 --> 00:09:43,790 And what did we contain, it will contain all the farm data in the form of a dictionary object, and 108 00:09:43,830 --> 00:09:46,070 that object will be called reserved. 109 00:09:47,390 --> 00:09:47,720 Right. 110 00:09:47,810 --> 00:09:52,910 So using this result dictionary object as a parameter. 111 00:09:54,760 --> 00:10:01,980 The another template result, Estevan, which is also present in the template for folder, will be rendered 112 00:10:01,990 --> 00:10:03,820 by this result function. 113 00:10:03,970 --> 00:10:06,840 So render template result that e-mail. 114 00:10:08,560 --> 00:10:12,360 What is there in the world today that we shall see, but it will. 115 00:10:13,360 --> 00:10:19,900 The result of the e-mail template will be provided another parameter or attribute result is equal to 116 00:10:19,900 --> 00:10:20,380 what it is. 117 00:10:20,710 --> 00:10:21,340 This is the. 118 00:10:23,170 --> 00:10:24,880 Name of the dictionary variable. 119 00:10:26,510 --> 00:10:31,960 Rather, this is the barometer to be provided to that template and this is the dictionary object reserved. 120 00:10:32,210 --> 00:10:34,760 This is the result that have been defined here. 121 00:10:35,980 --> 00:10:44,800 So, in effect, what is going to happen as this of starts, a formidable display form will be filled 122 00:10:44,800 --> 00:10:47,230 by the user submitted to this result. 123 00:10:48,160 --> 00:10:55,810 And it will fetch the entire form data into the desert object, and that will be rendered to this Liselotte 124 00:10:55,810 --> 00:10:56,320 estimate. 125 00:10:56,590 --> 00:11:00,350 So finally, what remains what is present in this estimate? 126 00:11:03,550 --> 00:11:12,580 So this is the result of a stable template starts with the mandatory DOCTYPE e-mail tag. 127 00:11:13,850 --> 00:11:18,080 And this is the rest of the esteemable, this is what is the. 128 00:11:21,830 --> 00:11:23,090 Ginge to templated. 129 00:11:24,450 --> 00:11:25,980 Uh, you know, instructions. 130 00:11:27,020 --> 00:11:28,190 So all those. 131 00:11:31,000 --> 00:11:39,520 Conditionals, explanations and loop statements are used or written in this case, the curly bracket 132 00:11:39,670 --> 00:11:40,180 and. 133 00:11:41,260 --> 00:11:47,980 But since nine, on one hand, on one side and percent on the and the writing on the record in between 134 00:11:47,980 --> 00:11:50,220 these, you are writing it for Luke. 135 00:11:51,930 --> 00:11:58,560 And these four loop were result, not ITR items, what is it, what items it will fetch an iterator 136 00:11:59,340 --> 00:12:07,350 for the dictionary object called isn't so it items from a third of the dictionary object is used to 137 00:12:08,100 --> 00:12:10,460 return any tretter. 138 00:12:11,160 --> 00:12:16,850 And you know that the dictionary object is a collection of items. 139 00:12:16,860 --> 00:12:19,330 Each item is a key value pair. 140 00:12:19,620 --> 00:12:21,240 So for each. 141 00:12:22,200 --> 00:12:31,560 He will appear in the end result of what we are doing, you are just putting the value of key and value, 142 00:12:32,430 --> 00:12:35,190 key and value are put into the. 143 00:12:36,530 --> 00:12:44,840 Roll off a table in the first sale of the roll, your display in key, second sale of the role, you 144 00:12:44,840 --> 00:12:45,800 are displaying the value. 145 00:12:45,810 --> 00:12:51,830 So all the text boxes that you enter name physics, chemistry, mathematics. 146 00:12:54,090 --> 00:12:54,780 The. 147 00:12:56,550 --> 00:13:01,720 Names of the keys and associated values will be displayed in the table, so as a result, what you should 148 00:13:01,720 --> 00:13:05,770 see, you should see a table being generated on your. 149 00:13:06,640 --> 00:13:07,240 Brazil. 150 00:13:08,070 --> 00:13:17,460 OK, so these are the three parts, one is the Python script, which is a flask sort of application, 151 00:13:17,480 --> 00:13:20,800 second is the form and third is the template. 152 00:13:22,170 --> 00:13:24,840 So let us see one by one how. 153 00:13:25,950 --> 00:13:29,510 The result ultimately comes onto your browser. 154 00:13:30,700 --> 00:13:31,840 So first, let me. 155 00:13:33,930 --> 00:13:41,700 You know, started this battle group, formed DataDot Pivo, in which the two are slash and slash result, 156 00:13:41,970 --> 00:13:47,130 are defined their bond with two functions one one first function is. 157 00:13:49,020 --> 00:13:53,160 You know, displaying the form and the other is displaying the result. 158 00:13:54,200 --> 00:13:54,850 Of the. 159 00:13:56,190 --> 00:13:58,890 Formed a tie into a table, so start the server. 160 00:14:01,890 --> 00:14:03,720 And go to the browser. 161 00:14:06,350 --> 00:14:08,310 So the brother is. 162 00:14:15,160 --> 00:14:22,840 Here and just you know, you are a local news veteran, backslash Delenda the form. 163 00:14:24,340 --> 00:14:25,420 Under the data. 164 00:14:29,490 --> 00:14:29,970 And. 165 00:14:31,580 --> 00:14:37,070 Press the submit button, what happens, the form that will be posted to the result? 166 00:14:37,160 --> 00:14:46,460 You are in the associated review function will fetch the form databasing request or form in addition 167 00:14:46,460 --> 00:14:47,070 to the object. 168 00:14:47,210 --> 00:14:52,880 And that dictionary object will be rendered by result of the activity in which there is a danger to 169 00:14:52,880 --> 00:14:55,070 template code which runs so far. 170 00:14:55,070 --> 00:14:57,320 Luban generates a table. 171 00:15:00,050 --> 00:15:00,770 Like this. 172 00:15:01,790 --> 00:15:06,550 And this is the final output of our entire flask application activity.