-
Title:
Hello Webapp World - Web Development
-
Description:
-
Okay, so let's move on to some live web applications.
-
So, at the end of your last homework, you should have
-
Google App Engine running on your machine, and you should have a basic site online.
-
We're going to start with basically the simple hello world example
-
that Google has on their site, which I have.
-
This is the main hello world Python file from the Google App Engine example page,
-
and it's got 2 main sections.
-
We'll start with this section down here at the bottom.
-
This is the URL mapping section, and in this case,
-
we have 1 URL, slash, and it maps to a handler called MainPage.
-
MainPage is defined in this class called MainPage.
-
It inherits from webapp to RequestHandler, which is the generic
-
request handler from Google.
-
If you don't know what classes are, you can learn about them offline.
-
It's basically a convenient way for grouping together
-
functions and data that are all related to the same thing.
-
We're not going to spend a whole lot of time on it here,
-
but you should be able to keep up just fine.
-
Our class has a function called get, which takes a parameter called self,
-
which is the common first parameter to most Python methods.
-
So, this function does 2 things.
-
First, it takes self.response, which is the kind of global response object
-
that this framework uses, and it sets a header.
-
It sets the Content-Type header to equal text/plain.
-
By default, the content type is text/html, but in this case it's setting it to text/plain,
-
and then it's writing the string "Hello, webapp World!"
-
If we start up Google App Engine, I'll start Google App Engine in my terminal here,
-
and then I'll go to my browser and load the page, and this is what we see.
-
We see that string that our program was writing out in our browser, "Hello, webapp World!"
-
Pretty neat.