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