So, I wanted to take time to talk about
how truly powerful Python is and why it's
so powerful. So, a lot of what I see when
people learn Python is they'll get a handle
on the syntax, and the internal functions,
and the way to use Python, and they're
kind of wondering like well how is this
practical. What can I do or, you
know, they're basically missing modules.
And so modules are the way that Python
has been extended to be such a great
environment to program in. So, we're going
to be looking at one specific
extensions or module in Python, we're
going to install it, and we're going to
start using it. So, what we're going to do
in the next video we're going to deploy
our Python application through Apache, so
we're going to be using a Python module
called WebPy. And what WebPy does is
basically it just allows us to use Python
to serve a webpage. So, what we're going
to do first install the module, so type
sudo pip install web.py. Now I've
already got it installed,
you guys should see a little download
progress bar and it should return
with a success message, and once it does
you can start using WebPy. So, I'm going
to actually open up gedit right now, and
we're going to start using it. I'm
just going to set up a basic example of
this web.py. So, let's first #!/
usr/bin/python. Now, here's how to import
modules in Python. You just type
import and we're going to import web.
We're going to set a variable called
urls = ( ) So, we actually have to do
something first. Python requires four
space indentation, and gedit is
automatically set up by default to do
eight spaces. We're going to change that to four, jump out of
here, now here we are going to define
routes. So, the route is going to reference
a class called myClass, that's it.
We're going to create that class.
So, class myClass: and in the class basically
what returns the HTML is the method
get. So, def GET(self): and for
right now let's just return "<h1>Hello
World</h1>"
Now at the bottom here outside of that
class we're actually going to set the
application variable = web.app. So,
application = web.application, and
we're going to instantiate this here. So,
the first parameter is urls, we're going to take
our routes up there, and then globals ( )), and that's it actually.
And then .wsgifunc( ), and that's it. So, let's
save, and I'm going to save this into our
HTML directory actually. So, var, www, html,
going to create a new directory here. I'm
going to call it
python, and in here I'm going to call
this file main.py.
So, if we have multiple classes that we
wanted to return multiple routes
basically what I would do is about
secondClass like that, and I could
define my second class here, and I would
basically just define the get method the
exactly same way, pass it self, and then return
an HTML string.
And I mean you could even load up a
HTML template file from files here, and
you know inject variables into the
templates HTML files, and return that as a
string, and that's a more practical
application but we're not going to get
that in-depth into it. Going to save this
here, and that's all we need to do. So, in
the next video we're going to be
installing an Apache module in order to
serve this up through Apache, and we will
configure a virtual host for it. So, thanks
for watching this I hope you guys liked it.