1 00:00:00,000 --> 00:00:04,396 [MUSIC] 2 00:00:04,396 --> 00:00:07,950 Hi I'm Kenneth and I'm a Django teacher for Treehouse. 3 00:00:07,950 --> 00:00:11,465 Building applications in Django isn't the most difficult thing in the world and 4 00:00:11,465 --> 00:00:13,190 you've probably built a couple by now. 5 00:00:13,190 --> 00:00:15,430 Either with Tree House or on your own. 6 00:00:15,430 --> 00:00:19,309 Once you build your project though, you'll want the world to see it. 7 00:00:19,309 --> 00:00:23,853 Years ago, deploying Python and Django sites was, well, it wasn't fun. 8 00:00:23,853 --> 00:00:27,573 I remember keeping a very long text file of all the steps I needed to do to get 9 00:00:27,573 --> 00:00:31,780 updates deployed on a site I built on a very early version of Django. 10 00:00:31,780 --> 00:00:35,500 Thankfully, services like PythonAnywhere exist now that make this a lot simpler. 11 00:00:37,020 --> 00:00:39,410 Unlike some platform as a services, 12 00:00:39,410 --> 00:00:43,140 PythonAnywhere gives you live access to a server through a web browser. 13 00:00:43,140 --> 00:00:46,630 It's actually pretty similar to how workspaces works here at Treehouse. 14 00:00:46,630 --> 00:00:50,400 PythonAnywhere is a bit more involved than some platforms like Heroku, but 15 00:00:50,400 --> 00:00:52,930 it's a better service if you want to know more about the underlying 16 00:00:52,930 --> 00:00:54,870 technology of your site. 17 00:00:54,870 --> 00:00:55,500 Stick around and 18 00:00:55,500 --> 00:00:58,625 I'll show you how to put your Django site live on the Internet at PythonAnywhere. 19 00:01:00,190 --> 00:01:03,850 So, I'm gonna start with a quick overview of the PythonAnywhere dashboard. 20 00:01:03,850 --> 00:01:07,570 So, in your web browser, go to pythonanywhere.com and go ahead and 21 00:01:07,570 --> 00:01:08,150 log in, 22 00:01:08,150 --> 00:01:11,840 if you're not logged in already or sign up if you haven't created an account yet. 23 00:01:11,840 --> 00:01:15,790 You should land immediately on this Consoles tab. 24 00:01:15,790 --> 00:01:20,900 Now, I wanna remind you that I have no control overall PythonAnywhere looks like, 25 00:01:20,900 --> 00:01:24,200 so this may very well look different by the time that you come here. 26 00:01:24,200 --> 00:01:25,650 But as of the time of this recording, 27 00:01:25,650 --> 00:01:27,550 this is what PythonAnywhere looks and works like. 28 00:01:28,590 --> 00:01:31,850 So, Consoles is where you can create new consoles or 29 00:01:31,850 --> 00:01:34,780 shells in the PythonAnywhere environment. 30 00:01:34,780 --> 00:01:37,930 So, you can go into Bash, you can go into MySQL, you can go into different 31 00:01:37,930 --> 00:01:41,280 versions of Python, you can even create custom consoles. 32 00:01:41,280 --> 00:01:42,870 We'll be using this tab and 33 00:01:42,870 --> 00:01:46,630 the PythonAnywhere Consoles very heavily during this workshop. 34 00:01:46,630 --> 00:01:51,580 If I click on the Files tab, I'm given this web based file manager. 35 00:01:51,580 --> 00:01:53,280 Now, I'm not gonna be using this much, 36 00:01:53,280 --> 00:01:55,990 since most of the file management is going to happen either 37 00:01:55,990 --> 00:02:00,670 in one of the PythonAnywhere consoles or in the console on my own computer. 38 00:02:01,740 --> 00:02:04,570 But this is a place where you can go and you can edit your files, 39 00:02:04,570 --> 00:02:08,770 move them between folders, create and delete folders, all of that kind of stuff, 40 00:02:08,770 --> 00:02:15,040 to control your files and everything that lives in your PythonAnywhere world. 41 00:02:15,040 --> 00:02:17,452 If I move over here to the Web tab, 42 00:02:17,452 --> 00:02:22,490 this is a mostly empty screen, there's a button for creating a new web app. 43 00:02:22,490 --> 00:02:26,560 I'll be coming back to this when I'm ready to deploy my Django project. 44 00:02:26,560 --> 00:02:31,810 If I click the Schedule tab, I can see PythonAnywhere's web based task scheduler. 45 00:02:31,810 --> 00:02:36,370 Now the project that I'm gonna deploy doesn't need scheduled tasks but 46 00:02:36,370 --> 00:02:39,040 depending on what you end up building and putting on PythonAnywhere, 47 00:02:39,040 --> 00:02:43,520 you may find yourself needing to run a task on a repeating basis, right? 48 00:02:43,520 --> 00:02:48,750 So, you need to send out a new email to people every hour, 49 00:02:48,750 --> 00:02:52,720 or you need to run some sort of cleanup script every ten minutes or whatever. 50 00:02:52,720 --> 00:02:53,620 This is where you would do that. 51 00:02:54,630 --> 00:02:58,384 The last tab is the Databases tab, and here you can see settings for 52 00:02:58,384 --> 00:03:03,079 a default MySQL database, and that's what we're gonna be connecting our app to, 53 00:03:03,079 --> 00:03:05,110 in the last video of this workshop. 54 00:03:05,110 --> 00:03:09,532 For now though, I'm gonna jump all the way back over here to the Consoles tab and 55 00:03:09,532 --> 00:03:13,501 I'm gonna start getting PythonAnywhere set up for my Django project. 56 00:03:13,501 --> 00:03:18,840 So, I don't wanna launch a Python, iPython or PyPy shell at the moment. 57 00:03:18,840 --> 00:03:21,300 I need to launch a Bash shell. 58 00:03:21,300 --> 00:03:24,997 So, I'm gonna do that by right clicking where it says, Bash, and 59 00:03:24,997 --> 00:03:27,190 I'm gonna select Open Link in New Tab. 60 00:03:27,190 --> 00:03:30,347 And this gives me the shell. 61 00:03:30,347 --> 00:03:31,931 And this should look pretty similar for 62 00:03:31,931 --> 00:03:34,380 those of you who have used workspaces before. 63 00:03:34,380 --> 00:03:37,420 This is very similar to the little console thing down at the bottom 64 00:03:37,420 --> 00:03:38,230 of your workspace. 65 00:03:39,320 --> 00:03:43,540 So, this is a Bash shell, just like you would get in Mac OS or Linux. 66 00:03:43,540 --> 00:03:46,850 And this is where I'm gonna set up the environment to hold my app. 67 00:03:46,850 --> 00:03:51,670 Now I want to have an isolated virtual environment for the app to run in, so 68 00:03:51,670 --> 00:03:55,830 that way I can control exactly what packages are being used for this app. 69 00:03:55,830 --> 00:04:00,976 So I'm gonna start by cloning my GitHub repo into my PythonAnywhere environment. 70 00:04:13,375 --> 00:04:17,372 Now I'm using a repo that's made for this workshop, you can, of course, 71 00:04:17,372 --> 00:04:19,600 use whatever repo your project lives in. 72 00:04:20,880 --> 00:04:22,952 So, I'll have to identify with GitHub. 73 00:04:30,392 --> 00:04:33,760 So I need to identify with GitHub, and then the cloning will actually happen. 74 00:04:33,760 --> 00:04:39,235 All right, so, now I have all the files on the PythonAnywhere server. 75 00:04:39,235 --> 00:04:43,780 So, now I'm gonna go into my project folder, which is called deploying_django, 76 00:04:43,780 --> 00:04:47,056 and I'm gonna create a virtual environment for my project. 77 00:04:47,056 --> 00:04:51,995 I'm gonna do this by using the mkvirtualenv, or 78 00:04:51,995 --> 00:04:54,768 make virtualenv command. 79 00:04:54,768 --> 00:04:58,166 And I wanna tell it which Python I want, which is Python 3.5. 80 00:04:58,166 --> 00:05:01,230 And then the name for the virtual environment which is a venv. 81 00:05:02,470 --> 00:05:05,570 This is a little different from how you've done virtual environments before on your 82 00:05:05,570 --> 00:05:10,280 machine, where you've done like the python -mvenv command or 83 00:05:10,280 --> 00:05:13,250 python 3 -mvenv. 84 00:05:13,250 --> 00:05:17,000 This is using the virtualenv wrapper library, 85 00:05:17,000 --> 00:05:22,740 which consolidates your virtual environments into one central location. 86 00:05:22,740 --> 00:05:25,800 Which in this case, you can see here, it's in home/kennethtreehouse, 87 00:05:25,800 --> 00:05:29,500 which is my PythonAnywhere username.virtualenvs, 88 00:05:29,500 --> 00:05:32,890 this is where all of them live, instead of living in the project directory. 89 00:05:34,150 --> 00:05:38,443 This installation takes a little bit of time, so I'm gonna just let this run. 90 00:05:38,443 --> 00:05:41,750 And then when it's done, now I'm gonna check to make sure that I'm using 91 00:05:41,750 --> 00:05:44,010 the Python that I just told it to use. 92 00:05:44,010 --> 00:05:47,000 I can see that the virtual environment has been activated but 93 00:05:47,000 --> 00:05:49,170 I just wanna double check. 94 00:05:49,170 --> 00:05:53,490 So, if I do which python, I see that it's this one that was up here. 95 00:05:53,490 --> 00:05:58,120 And if I was to do a python --version, then I see that it's 3.5, 96 00:05:58,120 --> 00:06:00,450 which is the Python I told it to use. 97 00:06:00,450 --> 00:06:03,590 So, now everything is set up and it's ready for 98 00:06:03,590 --> 00:06:08,125 me to start getting the project actually live and deployed on PythonAnywhere.