1 00:00:00,600 --> 00:00:07,290 Hello, friends, in this video, we shall see what are the static files in a flask application. 2 00:00:11,380 --> 00:00:17,500 So in the last application so far, we have seen that there is a python code and then there is a template, 3 00:00:17,890 --> 00:00:26,410 the template is essentially a civil war in which certain variable parties to be inserted with the help 4 00:00:26,410 --> 00:00:27,890 of the ginger to template. 5 00:00:28,570 --> 00:00:35,320 But as HTML, part of the webpage often requires the help of certain static files. 6 00:00:36,130 --> 00:00:43,060 For instance, you may be requiring certain CSS or cascaded stylesheets you may be requiring or you 7 00:00:43,060 --> 00:00:47,850 may require certain JavaScript which will be executing some client side functions. 8 00:00:48,160 --> 00:00:54,260 So these static files are often required for the execution of a template. 9 00:00:55,330 --> 00:01:02,530 So these static files are generally put into another special folder, just like the templates folder 10 00:01:02,530 --> 00:01:03,760 to store the templates. 11 00:01:04,270 --> 00:01:07,950 The static files are placed in a folder called static. 12 00:01:09,040 --> 00:01:17,290 So you have to have a folder by the name Static in which either those yeses are dodgiest, such such 13 00:01:17,290 --> 00:01:18,610 like files are put. 14 00:01:19,810 --> 00:01:28,210 So this static folder must be provided inside the application in order to identify the location of these 15 00:01:28,210 --> 00:01:29,050 static files. 16 00:01:29,410 --> 00:01:35,400 A special endpoint called a static is used to generate the URL for those files. 17 00:01:36,370 --> 00:01:39,350 So you are in for static, you are for static. 18 00:01:40,360 --> 00:01:44,520 This is the folder in which the static files will be there. 19 00:01:44,920 --> 00:01:49,390 For example, you are going to refer to a file called Styluses. 20 00:01:49,840 --> 00:01:58,560 So the manner in which this you are in for a function that uses you are all for static. 21 00:01:58,570 --> 00:01:59,490 The name of the folder. 22 00:01:59,500 --> 00:02:02,980 By default it is static filename is equal to your file. 23 00:02:02,980 --> 00:02:05,250 You want things that are distributed. 24 00:02:05,890 --> 00:02:13,190 There are two application settings that you can use in order to configure your application. 25 00:02:13,600 --> 00:02:15,970 One is AP not static. 26 00:02:15,970 --> 00:02:16,960 You are in part. 27 00:02:19,240 --> 00:02:25,820 Well, the static you are all parties by default, are part of the static folder, but you may choose 28 00:02:25,820 --> 00:02:30,570 to put your static files in some some at somewhere else or in some different folder. 29 00:02:30,950 --> 00:02:33,710 So in this case, you will find this spot. 30 00:02:35,090 --> 00:02:39,110 Otherwise, by default, it defaults to the path of the static folder. 31 00:02:39,620 --> 00:02:45,770 Similarly, under another configuration setting, also you can use FPP, not static folder. 32 00:02:46,040 --> 00:02:53,900 Again, the default name of the static folder is static in the same application folder. 33 00:02:53,930 --> 00:02:56,520 If it is different than you can mention it. 34 00:02:56,920 --> 00:02:58,460 Static folder is something else. 35 00:02:58,790 --> 00:03:03,010 So these are the two configuration settings which you rarely meet actually. 36 00:03:03,860 --> 00:03:08,480 But then that is possible or available. 37 00:03:08,840 --> 00:03:17,540 So what we will do, we will write a pattern called have a view function, make it render a template 38 00:03:17,540 --> 00:03:23,600 and the template is going to use a static file called it in this in our example, it is used. 39 00:03:23,960 --> 00:03:27,860 So let us see with the help of example how the static file is used. 40 00:03:28,760 --> 00:03:30,110 So just as the. 41 00:03:31,060 --> 00:03:39,300 The pledge to be rendered in a flask application are, you know, stored or put into a folder called 42 00:03:39,310 --> 00:03:40,690 as templates. 43 00:03:41,140 --> 00:03:52,000 Similarly, all the static files which are really needed for the execution of the webpages or templates, 44 00:03:52,000 --> 00:03:59,620 for instance, there may be any JavaScript files or there may be any Gasconade stylesheet case files. 45 00:04:00,040 --> 00:04:04,330 They will be stored in another special folder called a Static. 46 00:04:05,260 --> 00:04:10,720 In which four in this example I am going to store, if I call that Hello Rajas. 47 00:04:12,870 --> 00:04:19,260 So this Rogers is still in the static folder in your flask application. 48 00:04:21,040 --> 00:04:28,270 So what is the purpose of this project, because in this project, I have defined a function policy 49 00:04:28,420 --> 00:04:30,820 law which will be executed when. 50 00:04:31,740 --> 00:04:34,560 I click this button, so there is a on the. 51 00:04:37,250 --> 00:04:45,140 You know, homepage or Web page, and I'm just creating a button on click event of this button will 52 00:04:45,560 --> 00:04:48,880 fire this Halo function, which is in the Halo Rogers. 53 00:04:50,100 --> 00:04:57,420 So that I have to the world for this, I have to give to this script tibaijuka to text JavaScript SRT, 54 00:04:57,750 --> 00:05:03,720 you must be aware of the syntax with which you define the. 55 00:05:05,670 --> 00:05:09,390 Location of the JavaScript file in your webpage. 56 00:05:10,050 --> 00:05:12,110 So what is the URL for this file? 57 00:05:12,240 --> 00:05:13,140 Heterogenous. 58 00:05:14,930 --> 00:05:21,890 A special endpoint called Static is used, and it's Eurail is operated by a well-known we already use 59 00:05:21,900 --> 00:05:24,940 this function, you are informed, so you are ready for static. 60 00:05:25,670 --> 00:05:28,470 It will obtain the you are for this static folder. 61 00:05:28,940 --> 00:05:33,640 Another argument to this are for function is the filename is equal to this. 62 00:05:34,400 --> 00:05:37,520 So whatever the you are in for this. 63 00:05:37,530 --> 00:05:39,410 Hello Rogers will be faced by this. 64 00:05:39,410 --> 00:05:43,760 You are all for function will be given the value of this SIRC parameter. 65 00:05:44,780 --> 00:05:49,910 Uh, for script, script type is equal to the text of JavaScript. 66 00:05:50,510 --> 00:05:51,920 OK, so this completes our. 67 00:05:54,270 --> 00:05:58,020 Discussion of the template in this example. 68 00:05:58,670 --> 00:05:59,090 OK. 69 00:06:01,960 --> 00:06:08,500 Now, this is the this is the JavaScript file, which I am talking about, hello, Rogers has one function 70 00:06:08,500 --> 00:06:08,970 defined. 71 00:06:09,310 --> 00:06:09,870 Say hello. 72 00:06:09,880 --> 00:06:15,130 All it is doing is when the function is executed, it will pop up a hello world, Mrs.. 73 00:06:16,230 --> 00:06:23,640 OK, so this is the Java script file, which is stored in the static folder in our flask application. 74 00:06:25,120 --> 00:06:28,750 So this is my last application folder in which. 75 00:06:29,760 --> 00:06:31,980 The template for that is there in which. 76 00:06:33,820 --> 00:06:40,630 This index, not esteemable, is already there and there is a static folder in which this is installed. 77 00:06:41,200 --> 00:06:48,640 OK, so the template and the JavaScript file are already available in your application. 78 00:06:50,190 --> 00:06:55,530 Now we shall have a look at the python part of the entire called. 79 00:06:56,650 --> 00:06:57,610 It is very simple. 80 00:06:57,850 --> 00:07:05,730 All it is doing is defining you are Elul slash by the roof, decorated and associated. 81 00:07:05,980 --> 00:07:15,250 Arbon function is index and it is doing nothing but rendering an index that is multiplied by the function 82 00:07:15,250 --> 00:07:16,240 called render. 83 00:07:17,170 --> 00:07:22,090 So what I am going to do, I start this hour of course, and then I'll give you. 84 00:07:22,480 --> 00:07:28,330 Uh, the browser will be given the you are less localhost 5000 slash. 85 00:07:29,450 --> 00:07:35,840 OK, so what will happen, the index function will be executed, a view function index will render the 86 00:07:35,840 --> 00:07:37,040 index not estimate. 87 00:07:38,080 --> 00:07:44,290 For this index indexer, internally, it is requiring the Rajas, which I have already mentioned. 88 00:07:45,870 --> 00:07:54,180 By using the you are never static, OK, so let us see, one by one the activity started the server, 89 00:07:54,480 --> 00:07:57,860 open the browser, give the you are in and see the result. 90 00:08:01,090 --> 00:08:02,680 So the python called. 91 00:08:04,310 --> 00:08:06,050 To define that. 92 00:08:07,870 --> 00:08:13,060 You are all is present in the static dorber to render in index. 93 00:08:13,660 --> 00:08:20,950 So I will execute that static dorper from the python prompt and start the server. 94 00:08:23,270 --> 00:08:31,100 OK, so it is only now, starting now, we have to go to the browser and go to localhost. 95 00:08:35,250 --> 00:08:35,970 Slash. 96 00:08:38,440 --> 00:08:40,600 So the result of estimate will be rendered. 97 00:08:42,620 --> 00:08:44,620 However, to say hello, that was. 98 00:08:45,520 --> 00:08:47,240 There in the festival hall. 99 00:08:47,890 --> 00:08:53,990 Now, if I click on this, the only event will call the say hello function, which is defined indeed. 100 00:08:54,190 --> 00:08:55,180 Hello Rogers. 101 00:08:55,570 --> 00:09:01,240 The URL for which is obtained by the you are an underscore for function. 102 00:09:02,530 --> 00:09:05,260 And you should see this, Hallowell. 103 00:09:06,410 --> 00:09:08,720 Alert message, which is generated by. 104 00:09:09,950 --> 00:09:13,310 Uh, hello, gorgeous script. 105 00:09:14,410 --> 00:09:21,790 OK, so all the static files are put in the folder static, which is which should be present in the 106 00:09:22,000 --> 00:09:22,930 flask application.