PythonAnywhere provides a platform for deploying python-based web applications, but it’s web server takes a bit of configuring. Let’s take a look at how you configure PythonAnywhere to use the correct virtual environment and WSGI settings.
So my virtual environment is set up, my requirements are all installed, 0:00 it's time to get this project running on the actual pythonanywhere web server. 0:04 So I'm gonna come back over here to the dashboard, so not the console's tab and 0:08 I'm gonna click on the Web tab up here at the top and 0:13 I'm gonna choose Add a new web app button. 0:17 Now for this workshop and for a lot of the things that you're gonna deploy cuz you're 0:20 just wanting to test something out, show something to friends, 0:24 things like that, it's totally fine to use the free version of Pythonanywhere. 0:27 So go ahead and click Next, and you get this list of preconfigured stuff. 0:31 Pythonanywhere gets used for deploying a lot of Python stuff. 0:38 So they have some preconfigured deployments for 0:43 different Python web frameworks. 0:46 I want to control a lot of things though, so I'm gonna choose Manual configuration. 0:50 And now I need to choose the Python version that I'm using, I'm using Python 0:54 3.5 and then I'm gonna click Next, so that I can handle all the manual configuration. 0:58 Now there are a lot of options in here .So I'm gonna walk you through several of them 1:05 once it switches over there. 1:09 You can see it's working as it has a little spinning icon thing. 1:11 The first thing to talk about is this big green button right here at the top. 1:14 Any time you change your configuration and you want to make that configuration go 1:18 live, you're gonna click this Reload button and that's gonna restart your 1:22 deployment or it's like restarting the server so that people can see the changes. 1:27 The next thing to notice is this big orange 1:32 yellow button which says Run until three months from today. 1:34 If you're on the free plan, Python will rerun your app for three months. 1:38 If you want it to run longer than three months, 1:42 in three months you have to come back and click this button again. 1:44 If you're paying though, that doesn't happen. 1:48 So if you have something that's running and you want it to keep running for 1:50 a long time and you don't mind paying a little bit of money, 1:54 then this is a good reason to upgrade. 1:58 Okay, so now, let me go down here to the code section. 2:01 Now there's two things here that I need to change. 2:05 The first thing I need to change is the working directory. 2:08 So I want to set this to be the directory that my code lives in, 2:11 so my code lives here inside this djangoal directory. 2:16 So PWD, this is effectively what I want to put in there, so 2:25 I could actually just copy that and paste it into there. 2:30 And then I think I need a slash on the end of it to make Pythonanywhere happy so 2:39 that I clicked the little check mark. 2:42 The next thing I need to do is edit this WSGI configuration file. 2:44 So I'm gonna right click on that and choose Open in new tab and 2:48 this is the WSGI file that Pythonanywhere uses. 2:52 Now, I can't use the one that I put in my repo, 2:55 like I can't tell Pythonanywhere to just use that one. 2:59 But I'm going to keep it in my repo just so 3:03 that I have it for tracking changes that I make to it. 3:05 So, what I'm gonna do, is I'm gonna select all of this one, delete it, 3:10 come over here, select all of this one, copy it, and then paste it into here. 3:14 So, my WSGI file is now in here, but 3:19 it's not the WSGI file that's actually in my repo. 3:24 Then I'm gonna click Save and 3:26 then I can close this tab because I don't need it anymore. 3:28 And now I've got this whole thing set up. 3:32 Another thing that I want to configure is the Virtualenv because I wanna 3:36 use the packages that I installed. 3:40 So I'm gonna enter a path to a Virtualenv and 3:42 the path to my Virtualenv is /home/kennethtreehouse. 3:45 So that part there is going to change for you because It'll be your username. 3:51 And then Virtualenv's/venv. 3:55 And then I'm gonna click the check the mark again because that's 3:58 the Virtualenv that I created and installed all of my things too. 4:02 The cool thing is that now I could start a console here and 4:06 I'd have all my packages available and all of that kind of stuff. 4:09 Now before I reload my configuration, 4:12 there is one more thing I wanna point out to you. 4:15 And that's this Log files section. 4:17 So if you look right here there's three different Log files, 4:20 there's Access log, Error log and Server log. 4:23 If things go wrong, this is a place where you can come and 4:26 you can check these three Log files to see what is going on, right? 4:28 What things are being accessed, what errors are being thrown, 4:33 what does the server say, all of that kind of stuff. 4:36 To try and debug whatever problem you may be having. 4:38 Okay, this should all be done. 4:41 I'm gonna scroll up here and click Reload, and then when the spinner that's down here 4:44 stop spinning, I'll be able to go and check out my app and see if it works. 4:48 So let's that's spin, spin, spin, spin. 4:53 All right, and now I'm going to right click on here choose Open in new tab and 4:56 there's my Django app. 5:01 So if you followed on and you can see your Django app congratulations. 5:03 Take a minute, feel accomplished, enjoy the glow of having something live on 5:07 the internet, but don't send your link out just yet, 5:11 your deployed web app isn't quite ready for public consumption. 5:15 In the next video I'm gonna turn off some debug settings, 5:18 I'm gonna collect the static files so that White Noise can serve them better and 5:21 I'll make the app weigh more production ready. 5:26
You need to sign up for Treehouse in order to download course files.Sign up