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
In this video, we’ll start setting up our PythonAnywhere environment to make it ready for our app. We’ll get a virtual python environment set up, and get our app code into PythonAnywhere.
-
0:00
[MUSIC]
-
0:04
Hi I'm Kenneth and I'm a Django teacher for Treehouse.
-
0:07
Building applications in Django isn't the most difficult thing in the world and
-
0:11
you've probably built a couple by now.
-
0:13
Either with Tree House or on your own.
-
0:15
Once you build your project though, you'll want the world to see it.
-
0:19
Years ago, deploying Python and Django sites was, well, it wasn't fun.
-
0:23
I remember keeping a very long text file of all the steps I needed to do to get
-
0:27
updates deployed on a site I built on a very early version of Django.
-
0:31
Thankfully, services like PythonAnywhere exist now that make this a lot simpler.
-
0:37
Unlike some platform as a services,
-
0:39
PythonAnywhere gives you live access to a server through a web browser.
-
0:43
It's actually pretty similar to how workspaces works here at Treehouse.
-
0:46
PythonAnywhere is a bit more involved than some platforms like Heroku, but
-
0:50
it's a better service if you want to know more about the underlying
-
0:52
technology of your site.
-
0:54
Stick around and
-
0:55
I'll show you how to put your Django site live on the Internet at PythonAnywhere.
-
1:00
So, I'm gonna start with a quick overview of the PythonAnywhere dashboard.
-
1:03
So, in your web browser, go to pythonanywhere.com and go ahead and
-
1:07
log in,
-
1:08
if you're not logged in already or sign up if you haven't created an account yet.
-
1:11
You should land immediately on this Consoles tab.
-
1:15
Now, I wanna remind you that I have no control overall PythonAnywhere looks like,
-
1:20
so this may very well look different by the time that you come here.
-
1:24
But as of the time of this recording,
-
1:25
this is what PythonAnywhere looks and works like.
-
1:28
So, Consoles is where you can create new consoles or
-
1:31
shells in the PythonAnywhere environment.
-
1:34
So, you can go into Bash, you can go into MySQL, you can go into different
-
1:37
versions of Python, you can even create custom consoles.
-
1:41
We'll be using this tab and
-
1:42
the PythonAnywhere Consoles very heavily during this workshop.
-
1:46
If I click on the Files tab, I'm given this web based file manager.
-
1:51
Now, I'm not gonna be using this much,
-
1:53
since most of the file management is going to happen either
-
1:55
in one of the PythonAnywhere consoles or in the console on my own computer.
-
2:01
But this is a place where you can go and you can edit your files,
-
2:04
move them between folders, create and delete folders, all of that kind of stuff,
-
2:08
to control your files and everything that lives in your PythonAnywhere world.
-
2:15
If I move over here to the Web tab,
-
2:17
this is a mostly empty screen, there's a button for creating a new web app.
-
2:22
I'll be coming back to this when I'm ready to deploy my Django project.
-
2:26
If I click the Schedule tab, I can see PythonAnywhere's web based task scheduler.
-
2:31
Now the project that I'm gonna deploy doesn't need scheduled tasks but
-
2:36
depending on what you end up building and putting on PythonAnywhere,
-
2:39
you may find yourself needing to run a task on a repeating basis, right?
-
2:43
So, you need to send out a new email to people every hour,
-
2:48
or you need to run some sort of cleanup script every ten minutes or whatever.
-
2:52
This is where you would do that.
-
2:54
The last tab is the Databases tab, and here you can see settings for
-
2:58
a default MySQL database, and that's what we're gonna be connecting our app to,
-
3:03
in the last video of this workshop.
-
3:05
For now though, I'm gonna jump all the way back over here to the Consoles tab and
-
3:09
I'm gonna start getting PythonAnywhere set up for my Django project.
-
3:13
So, I don't wanna launch a Python, iPython or PyPy shell at the moment.
-
3:18
I need to launch a Bash shell.
-
3:21
So, I'm gonna do that by right clicking where it says, Bash, and
-
3:24
I'm gonna select Open Link in New Tab.
-
3:27
And this gives me the shell.
-
3:30
And this should look pretty similar for
-
3:31
those of you who have used workspaces before.
-
3:34
This is very similar to the little console thing down at the bottom
-
3:37
of your workspace.
-
3:39
So, this is a Bash shell, just like you would get in Mac OS or Linux.
-
3:43
And this is where I'm gonna set up the environment to hold my app.
-
3:46
Now I want to have an isolated virtual environment for the app to run in, so
-
3:51
that way I can control exactly what packages are being used for this app.
-
3:55
So I'm gonna start by cloning my GitHub repo into my PythonAnywhere environment.
-
4:13
Now I'm using a repo that's made for this workshop, you can, of course,
-
4:17
use whatever repo your project lives in.
-
4:20
So, I'll have to identify with GitHub.
-
4:30
So I need to identify with GitHub, and then the cloning will actually happen.
-
4:33
All right, so, now I have all the files on the PythonAnywhere server.
-
4:39
So, now I'm gonna go into my project folder, which is called deploying_django,
-
4:43
and I'm gonna create a virtual environment for my project.
-
4:47
I'm gonna do this by using the mkvirtualenv, or
-
4:51
make virtualenv command.
-
4:54
And I wanna tell it which Python I want, which is Python 3.5.
-
4:58
And then the name for the virtual environment which is a venv.
-
5:02
This is a little different from how you've done virtual environments before on your
-
5:05
machine, where you've done like the python -mvenv command or
-
5:10
python 3 -mvenv.
-
5:13
This is using the virtualenv wrapper library,
-
5:17
which consolidates your virtual environments into one central location.
-
5:22
Which in this case, you can see here, it's in home/kennethtreehouse,
-
5:25
which is my PythonAnywhere username.virtualenvs,
-
5:29
this is where all of them live, instead of living in the project directory.
-
5:34
This installation takes a little bit of time, so I'm gonna just let this run.
-
5:38
And then when it's done, now I'm gonna check to make sure that I'm using
-
5:41
the Python that I just told it to use.
-
5:44
I can see that the virtual environment has been activated but
-
5:47
I just wanna double check.
-
5:49
So, if I do which python, I see that it's this one that was up here.
-
5:53
And if I was to do a python --version, then I see that it's 3.5,
-
5:58
which is the Python I told it to use.
-
6:00
So, now everything is set up and it's ready for
-
6:03
me to start getting the project actually live and deployed on PythonAnywhere.
You need to sign up for Treehouse in order to download course files.
Sign up