controller code
Controlling your App Engine webapp Like your other webapps, it makes sense to arrange your webapp controller code within a specific folder structure. Here’s one suggestion:
to be Your top-level folder needs ati on” line plic “ap the named to match in your webapp’s “app.yaml” file.
Put all of your webapp’s controller code and configuration files in here.
hfwwgapp
static
templates
As you’ve seen, any CGI can run on GAE, but to get the most out of Google’s technology, you need to code to the WSGI standard. Here’s some boilerplate code that every WSGI-compatible GAE webapp starts with:
Import App Engine’s “webapp” class.
If you have static content, nt, put it in here (at the mome this folder is empty). Put your HTML templates in here.
Import a utility that runs your webapp.
from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app
This class responds to a web request from your web browser.
class IndexPage(webapp.RequestHandler):
Create an new “webapp” object for your application.
def get(self): pass
request This method runs when a GET web is received by your webapp.
This is not unlike switching on CGI tracking.
app = webapp.WSGIApplication([('/.*', IndexPage)], debug=True) def main(): run_wsgi_app(app) if __name__ == '__main__': main()
370 Chapter 10
Start your webapp. Just use these two lines of code as-
is.