1 00:00:00,360 --> 00:00:08,570 In this video, we shall see what are the templates as far as the flask application framework is concerned, 2 00:00:10,040 --> 00:00:17,070 but in this exercise we shall see how to use the template in a flask application. 3 00:00:18,900 --> 00:00:20,010 We have seen that. 4 00:00:21,080 --> 00:00:28,820 Any of you function, which is, you know, mapped with a particular rule or a particular, you are 5 00:00:28,820 --> 00:00:36,410 in the function returns the text in the rather the output in the form of a plain text. 6 00:00:38,030 --> 00:00:45,440 So if you have written Hello, World, as we have written in the very first application, if you just 7 00:00:45,620 --> 00:00:52,550 return Hello World, that were the text Hello world is rendered in the form of a plain text, but it 8 00:00:52,550 --> 00:00:55,820 can be rendered in the form of an e-mail. 9 00:00:56,800 --> 00:01:05,680 If the string to be rendered is manually composed in the form of an e-mail text, for example. 10 00:01:06,730 --> 00:01:09,820 In the script, this is the You are el. 11 00:01:12,560 --> 00:01:15,860 This is the you are a rule which is bound with. 12 00:01:17,010 --> 00:01:18,540 This function called an index. 13 00:01:19,900 --> 00:01:25,120 And inside this index function, I have constructed a. 14 00:01:26,400 --> 00:01:35,070 Variable called the Star with the help of a triple coded string in which these e-mail tags are concatenated 15 00:01:35,070 --> 00:01:39,020 to form a simple e-mail. 16 00:01:42,360 --> 00:01:44,010 Hello, world, which is. 17 00:01:45,220 --> 00:01:55,090 You know, put inside the H1 and and and slash actual tags so that Hello world is expected to be displayed 18 00:01:55,420 --> 00:02:03,850 with the healing tag, that means it will be in a smaller format and this thing is now being returned 19 00:02:03,880 --> 00:02:05,290 when this function is called. 20 00:02:05,980 --> 00:02:08,960 So what do you expect after starting the service? 21 00:02:08,980 --> 00:02:16,270 If I just say localhost 5000, call backslash, then this index page index function, rather, will 22 00:02:16,270 --> 00:02:18,270 be, uh, executed. 23 00:02:18,280 --> 00:02:24,610 And Hello World is expected to be printed with H1 tag that means in Boulder font. 24 00:02:25,570 --> 00:02:27,190 So this is what we expect. 25 00:02:27,220 --> 00:02:32,500 This is a symbol, the same exercise of hello world that we did in the beginning, but now it is in 26 00:02:32,500 --> 00:02:33,670 the form of SGV. 27 00:02:34,390 --> 00:02:35,110 So let us see. 28 00:02:39,500 --> 00:02:43,600 So let me start the server by executing this hallowed out by. 29 00:02:47,020 --> 00:02:48,040 The server is running. 30 00:02:50,250 --> 00:02:56,880 No, I will just issue localhost Kolon 5000 slash, which will execute the index. 31 00:02:58,480 --> 00:03:02,830 Function, which is mapped and it will display high level. 32 00:03:04,070 --> 00:03:11,480 So this is a manual way of rendering e-mail to the browser via our view function. 33 00:03:12,950 --> 00:03:22,040 So now instead of manually rendering the text in the e-mail form to the browser, we shall now put that 34 00:03:22,090 --> 00:03:22,790 e-mail. 35 00:03:23,790 --> 00:03:27,600 You know, script into an HTML page and. 36 00:03:28,570 --> 00:03:30,550 Redirect our browser. 37 00:03:31,880 --> 00:03:38,450 From the view function directly to that particular e-mail page, by using the render template function 38 00:03:38,450 --> 00:03:40,410 in the flask in a module. 39 00:03:41,420 --> 00:03:50,660 So for that purpose, first I have created a simple hello world web page and it has to be stored in 40 00:03:50,660 --> 00:03:52,640 a templates folder in your. 41 00:03:53,950 --> 00:03:56,260 Application full, that means what? 42 00:03:59,570 --> 00:04:02,070 So this is going to be our e-mail. 43 00:04:03,200 --> 00:04:09,590 As rather, the Python script, which we will eventually run to start our. 44 00:04:11,640 --> 00:04:19,680 Serwer, This is the halo that were on the same level of which there must be a template for all this 45 00:04:19,680 --> 00:04:21,870 is, of course, our virtual environment. 46 00:04:22,950 --> 00:04:28,470 So at the sea, in the same direction in which this hollowed out power is there, create a folder called 47 00:04:28,470 --> 00:04:31,400 as templates and in which you stored this. 48 00:04:31,640 --> 00:04:32,710 Hello, David. 49 00:04:33,870 --> 00:04:34,210 Right. 50 00:04:35,880 --> 00:04:40,440 So this is what you need to do, know whenever you want to. 51 00:04:41,810 --> 00:04:47,760 Fire a template from the flask view function, that e-mail. 52 00:04:48,820 --> 00:04:51,780 Script must be present in this template folder. 53 00:04:56,480 --> 00:05:00,200 Now coming back to this hallowed out by Python script. 54 00:05:01,540 --> 00:05:09,460 You know, in order to render the template, you have to use a function called as rendered template 55 00:05:09,460 --> 00:05:12,830 itself, which is present in the flask model. 56 00:05:12,850 --> 00:05:16,930 So you have to imported from flask, import the flask. 57 00:05:18,250 --> 00:05:20,740 Glass and function relatively. 58 00:05:23,080 --> 00:05:32,590 So, like before this backslides, you are is bound to the index function now, instead of manually 59 00:05:32,590 --> 00:05:39,340 rendering the e-mail code, I'll just say return a template, which is the template that you want to, 60 00:05:39,340 --> 00:05:45,250 which is the e-mail that you want to render a LORADITCH will ensure that it is already present in the 61 00:05:45,550 --> 00:05:46,450 templates folder. 62 00:05:46,990 --> 00:05:48,580 So this is what you. 63 00:05:49,770 --> 00:05:58,090 Should write in the hallowed out by the Python script, which you will use for starting your sutler. 64 00:06:01,490 --> 00:06:06,960 So let us start the server by executing this alert by. 65 00:06:09,440 --> 00:06:10,310 This is now running. 66 00:06:11,210 --> 00:06:12,460 Go back to the browser now. 67 00:06:14,540 --> 00:06:15,080 And. 68 00:06:18,940 --> 00:06:23,200 And we the same moral localhost, 5000 backslash. 69 00:06:25,180 --> 00:06:31,300 Again, the Hollowell will be printed, another difference is that this Hallowell is now not rendered 70 00:06:31,300 --> 00:06:39,070 manually by creating a cascade or concatenate string, having extreme events, but rather there is a 71 00:06:39,820 --> 00:06:46,030 esteemable page e-mail in the template folder and that is being rendered as a template.