Request Lifecycle

These notes describe the lifecycle of a request and how it is handled by a web application developed with App Engine

Requests

The server accepts requests, which contain an action along with parameters. The actions can be:

* from a URL entered in the browser bar, e.g.,

    mysite.appspot.com/someaction?p1=joe&p2=bob

* from a submitted form:
    <form action="/someaction" method="get">
<input type="text" name="p1">
<input type="submit" value="Submit">
</form>

* or from a link:

    <a href="/someaction">click here</a>

The action is sent to the server along with its parameters.

Mapping Table

The mapping table tells the controller which class should handle each action

application = webapp.WSGIApplication (
                      [('/', WelcomePage),
                      ('/someaction',SomeHandler)
                                     ],
                                     debug=True)

Controller
: Event Handler

Each event handler does the following:
  • gets parameters from the request, e.g.,       p1=self.request.get('p1')
  • does some computations, perhaps access database, current user, session
  • either redirect to another page, or
  • set up some template values and render the new page...
Rendering a page looks like the following: 

    template_values={'person':person,'logout_url':logout_url}
    # render the page using the template engine
    path = os.path.join(os.path.dirname(__file__),'profile.html')
    self.response.out.write(template.render(path,template_values))


Note that the last essentially renders the html file specified in the line above, using the values in template_values to replace the template variables in {{  }}

Instead of rendering, we can redirect to a different action (url):

    self.redirect('/home')

The latter does not use the template_values, and it expects a request, not an HTML file, as its parameter. It also causes the URL in the browser bar to change, which is helpful at times.

Recent site activity