1 00:00:00,000 --> 00:00:03,629 Hi, welcome to a new lecture on how to 2 00:00:03,630 --> 00:00:07,080 deploy your flask web app on a live 3 00:00:07,080 --> 00:00:10,170 server, which means that you're going to 4 00:00:10,170 --> 00:00:13,050 have your own domain name, which you can 5 00:00:13,050 --> 00:00:14,850 give to anyone, and they can use your 6 00:00:14,850 --> 00:00:18,588 web app, and we're going to use PythonAnywhere. 7 00:00:18,612 --> 00:00:21,601 So go to pythonanywhere.com. 8 00:00:22,834 --> 00:00:25,083 PythonAnywhere has a free 9 00:00:25,200 --> 00:00:28,290 service, where you can host your flask 10 00:00:28,320 --> 00:00:30,360 applications. So this is what we're 11 00:00:30,360 --> 00:00:32,820 going to do, and it's relatively easy to 12 00:00:32,820 --> 00:00:35,340 deploy on PythonAnywhere, so this 13 00:00:35,365 --> 00:00:37,645 is an updated video, actually, of the course. 14 00:00:37,715 --> 00:00:41,075 Before of this, we used Heroku. Now, 15 00:00:41,100 --> 00:00:43,290 Heroku and PythonAnywhere both allow 16 00:00:43,290 --> 00:00:46,860 you to host, to deploy flask applications 17 00:00:46,860 --> 00:00:49,955 for free. The difference is that PythonAnywhere 18 00:00:49,979 --> 00:00:51,870 tends to be more user friendly. 19 00:00:52,440 --> 00:00:54,990 And Heroku, on the other hand, makes it 20 00:00:54,990 --> 00:00:59,070 harder, and so I usually suggest that as 21 00:00:59,070 --> 00:01:01,530 a programmer, you want to focus on your 22 00:01:01,530 --> 00:01:04,530 codes, instead of dealing with server 23 00:01:04,685 --> 00:01:07,385 administration issues. Although I would 24 00:01:07,410 --> 00:01:09,300 also like to say that both Heroku and 25 00:01:09,325 --> 00:01:11,425 PythonAnywhere are relatively easy 26 00:01:11,885 --> 00:01:16,625 compared to if you had your own server 27 00:01:16,650 --> 00:01:18,360 where you have to handle 28 00:01:18,360 --> 00:01:22,288 everything. So still Heroku and PythonAnywhere 29 00:01:22,312 --> 00:01:24,300 makes things easier. To be able 30 00:01:24,300 --> 00:01:27,021 to deploy your flask web app on PythonAnywhere, 31 00:01:27,045 --> 00:01:28,560 you need to sign up for an 32 00:01:28,585 --> 00:01:30,955 account, so go to Pricing & sign up, 33 00:01:31,020 --> 00:01:33,570 and you want to find the section where 34 00:01:33,570 --> 00:01:35,340 you can create a beginner account 35 00:01:35,340 --> 00:01:38,280 because that is free, and they also have 36 00:01:38,280 --> 00:01:40,830 other plans paid, so if you have more 37 00:01:40,830 --> 00:01:44,220 visitors, then you'd have to upgrade to 38 00:01:44,670 --> 00:01:46,830 a paid account. So I'm going to create a 39 00:01:46,855 --> 00:01:51,210 new account. All right, so I signed 40 00:01:51,210 --> 00:01:54,687 up, and my username is 41 00:01:54,712 --> 00:01:59,580 ardit12345. That's my username, and this is 42 00:01:59,580 --> 00:02:02,700 the dashboard. Now on PythonAnywhere, 43 00:02:02,940 --> 00:02:05,670 besides deploying web apps, you can also 44 00:02:05,670 --> 00:02:07,920 do some other things. So before we 45 00:02:07,920 --> 00:02:09,960 deploy the web app, let me give you a 46 00:02:10,380 --> 00:02:12,900 short tour on PythonAnywhere. 47 00:02:13,830 --> 00:02:15,690 Basically, you should be able to see the 48 00:02:15,720 --> 00:02:18,390 dashboard menu here, and then we have 49 00:02:18,390 --> 00:02:20,880 Consoles. In Consoles, if you go to 50 00:02:20,880 --> 00:02:24,630 Consoles, basically you can create a 51 00:02:24,630 --> 00:02:25,887 Bash console, 52 00:02:25,911 --> 00:02:30,685 [No audio] 53 00:02:30,710 --> 00:02:32,370 and that gives you access 54 00:02:32,370 --> 00:02:35,190 to your own server where you'll deploy 55 00:02:35,190 --> 00:02:38,280 your web app, and you could also do 56 00:02:38,280 --> 00:02:40,260 other things such as you can start 57 00:02:40,260 --> 00:02:45,660 python3, and it starts that version 58 00:02:45,660 --> 00:02:47,900 of Python. So it's an interactive python shell. 59 00:02:47,924 --> 00:02:50,108 [No audio] 60 00:02:50,133 --> 00:02:51,450 You can even import some 61 00:02:51,450 --> 00:02:53,190 libraries here. So pandas is already 62 00:02:53,190 --> 00:02:57,360 installed, you can use it. The downsides 63 00:02:57,390 --> 00:02:59,340 of this is that you don't have a 64 00:02:59,340 --> 00:03:02,820 Graphical User Interface. So if you want 65 00:03:02,820 --> 00:03:05,070 to show to generate some graphs, and you 66 00:03:05,070 --> 00:03:06,960 want to see them that's not possible on 67 00:03:06,960 --> 00:03:09,390 PythonAnywhere, because all you have is 68 00:03:09,390 --> 00:03:11,790 this shell. So the python shell and you 69 00:03:11,790 --> 00:03:16,080 go back to the terminal, and for example 70 00:03:16,080 --> 00:03:20,460 with pwd, you can see where you are 71 00:03:20,490 --> 00:03:22,560 currently. So that's your location in 72 00:03:22,560 --> 00:03:25,680 the server. So you are inside home, and 73 00:03:25,680 --> 00:03:29,130 then inside ardit12345, so that 74 00:03:29,130 --> 00:03:32,130 folder of the home folder. Here you can 75 00:03:32,130 --> 00:03:36,990 also create Python files, for example, 76 00:03:38,345 --> 00:03:45,515 nano example.py. So nano is a text 77 00:03:45,540 --> 00:03:48,360 editor, which you can use in this kind 78 00:03:48,360 --> 00:03:51,870 of command line interfaces. So that will 79 00:03:51,870 --> 00:03:53,880 create a new file, and here you can 80 00:03:53,880 --> 00:03:55,980 write Python code such as print 81 00:03:57,618 --> 00:03:58,643 Hello, 82 00:04:00,043 --> 00:04:03,000 parenthesis. Now, to save this 83 00:04:03,000 --> 00:04:04,680 file, what you want to do is you want to 84 00:04:04,680 --> 00:04:07,590 follow these commands. So exit, you want 85 00:04:07,590 --> 00:04:11,940 to exit with Ctrl X. So press Ctrl X, 86 00:04:12,117 --> 00:04:15,777 you'll see this message. It says Save 87 00:04:15,810 --> 00:04:18,030 modified buffer, which means do you want 88 00:04:18,030 --> 00:04:22,200 to save this file? Y for Yes or N for 89 00:04:22,200 --> 00:04:26,490 No. So I'm going to press Y and then it 90 00:04:26,490 --> 00:04:28,680 asks you again what name do you want to 91 00:04:28,925 --> 00:04:31,955 put to your file example.py as it is 92 00:04:32,019 --> 00:04:36,309 Yes. So just press Enter now, Enter and 93 00:04:36,420 --> 00:04:39,480 the file is saved. To run it, you do 94 00:04:39,480 --> 00:04:45,120 python3.9 example.py run and you 95 00:04:45,120 --> 00:04:47,640 get the output. So that's what you can 96 00:04:47,640 --> 00:04:50,280 do with the Console if you go back then 97 00:04:50,310 --> 00:04:55,590 you have this files, and here now you 98 00:04:55,620 --> 00:04:58,800 can see that example.py which we 99 00:04:58,800 --> 00:05:00,990 created previously is here, and you see 100 00:05:00,990 --> 00:05:05,255 the current directory, so home/ardit12345. 101 00:05:05,496 --> 00:05:08,280 That's the directory, we were in 102 00:05:08,280 --> 00:05:11,490 the command line interface. So this is 103 00:05:11,490 --> 00:05:14,490 another way to create files. So if you 104 00:05:14,490 --> 00:05:18,600 want to create a file here, you give a 105 00:05:18,600 --> 00:05:22,665 name in here, let's say example2.py 106 00:05:22,894 --> 00:05:24,391 and go to New File, 107 00:05:24,415 --> 00:05:27,384 [No audio] 108 00:05:27,414 --> 00:05:34,085 and let's say here I am print Hello Again, and 109 00:05:34,110 --> 00:05:37,050 now you can also run this file, save it 110 00:05:37,096 --> 00:05:39,646 and run it from here. So Save it first, 111 00:05:39,990 --> 00:05:44,255 and go to the Run button, and you should 112 00:05:44,280 --> 00:05:46,170 see the output down here. 113 00:05:46,194 --> 00:05:51,244 [No audio] 114 00:05:51,269 --> 00:05:53,879 This is a bit slower than the previous 115 00:05:53,879 --> 00:05:57,089 way to run application, to run Python 116 00:05:57,089 --> 00:05:59,339 files. But anyway, this is the output. 117 00:05:59,729 --> 00:06:01,619 So that's another way to run Python 118 00:06:01,619 --> 00:06:05,121 files. You want to go back now, you can press in here. 119 00:06:05,145 --> 00:06:07,694 [No audio] 120 00:06:07,719 --> 00:06:11,039 So this is a Files page 121 00:06:11,069 --> 00:06:15,209 and then we have Web. Here is where 122 00:06:15,209 --> 00:06:17,669 we will create a new web app, but in the 123 00:06:17,669 --> 00:06:20,669 next lecture, and then we have Tasks. 124 00:06:20,699 --> 00:06:23,819 With Tasks, what you could do is you 125 00:06:23,819 --> 00:06:28,529 could enter here, the path of one of 126 00:06:28,529 --> 00:06:31,949 your PythonAnywhere Python files. For 127 00:06:31,949 --> 00:06:34,799 example, if you, if I wanted to give the 128 00:06:34,799 --> 00:06:39,299 path of example.py, I would say 129 00:06:39,299 --> 00:06:42,809 home.ardit12345, the 130 00:06:42,809 --> 00:06:47,519 directory, and example.py, and then I 131 00:06:47,519 --> 00:06:50,517 would define a time, I would set a time here 132 00:06:50,734 --> 00:06:54,214 in UTC system, time system, and this 133 00:06:54,239 --> 00:06:57,419 script then would be executed at that 134 00:06:57,419 --> 00:07:02,039 time every day. This could be useful for 135 00:07:02,069 --> 00:07:04,079 things like web scraping, if you want to 136 00:07:04,079 --> 00:07:06,419 scrape something at a certain time every 137 00:07:06,419 --> 00:07:09,655 day. So you can do that on PythonAnywhere 138 00:07:09,679 --> 00:07:12,149 as well, and lastly, we have a 139 00:07:12,149 --> 00:07:16,379 Databases menu. Here is where you can 140 00:07:16,379 --> 00:07:19,739 create a database. So if your web app 141 00:07:20,069 --> 00:07:22,619 has a database where it saves the data, 142 00:07:22,769 --> 00:07:25,019 you want to create a new database here, 143 00:07:25,294 --> 00:07:26,824 and then create a table for that 144 00:07:26,849 --> 00:07:29,519 database. Again, it's, you can do that in 145 00:07:29,519 --> 00:07:31,739 this interface here in databases, and 146 00:07:31,739 --> 00:07:33,299 then your web app will be able to 147 00:07:33,299 --> 00:07:36,779 interact with this database. So this was 148 00:07:36,779 --> 00:07:39,989 an introduction to PythonAnywhere. In 149 00:07:39,989 --> 00:07:41,789 the next video, we're going to deploy 150 00:07:41,824 --> 00:07:45,604 our Python app, so our Flask app on 151 00:07:45,629 --> 00:07:47,433 PythonAnywhere, see you.