def main():
url_path=r'%s(.*)'
url_mappings=[]
for handler in [FirstRequestHandler,
SecondRequestHandler,
…,
RootRequestHandler]:
url_mappings.append((url_path%handler.app_url, handler))
from google.appengine.ext.webapp import WSGIApplication
application=WSGIApplication(url_mappings, debug=True)
from wsgiref.handlers import CGIHandler
CGIHandler().run(application)
First I setup a format string for the url_path associated with each handler. Each of my handlers has a field named app_url which is the prefix for all URLs associated with the handler. The final handler in the list in the RootRequestHandler and its app_url is ‘/’. I iterate over a list of handlers and set up the url_mappings list.
All of my handlers extend my BaseHandler. The BaseHandler has methods to create the base template dictionary, to handle get and post requests and to handle exceptions. Each of the Handlers implements the get method and imports their module and call the base classes handle method.

No comments:
Post a Comment