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">* 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:
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. |