webapp application has three parts:- one or more
RequestHandlerclasses that process requests and build responses - a
WSGIApplicationinstance that routes incoming requests to handlers based on the URL - a main routine that runs the
WSGIApplicationusing a CGI adaptor.
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
class MainPage(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.out.write('Hello World from the webapp framework!')
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main() |
| application: webapptest version: 1 runtime: python api_version: 1 handlers: - url: / script: webapp.py |
What the above code does
- The
webappmodule is in thegoogle.appengine.ext - This code defines one request handler,
MainPage, mapped to the root URL (/).We can map diffrent urls with diffrent handlers - When
webappreceives an HTTP GET request to the URL/, it instantiates theMainPageclass and calls the instance'sgetmethod. Inside the method, information about the request is available usingself.request. Typically, the method sets properties onself.responseto prepare the response.
No comments:
Post a Comment