YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Hello Webapp World - Web Development

Get Embed Code
5 Languages

Showing Revision 11 created 09/03/2017 by Dejan Trajkovic.

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