Python : GoogleApp WebApp2 & WSGI
GoogleApp with Python
Google App Hello WorldGoogle App webapp2 & WSGI
Uploading Google App Hello World
The Web Server Gateway Interface (WSGI) is a standardized interface between Web servers and Python Web frameworks/applications. The goal is to provide a relatively simple yet comprehensive interface capable of supporting interactions between a Web server and a Web framework.
Google App Engine includes a simple web application framework, called webapp2. The webapp2 framework is already installed in the App Engine environment and in the SDK.
A webapp2 application has two parts:
- RequestHandler classes that process requests and build responses
- WSGIApplication instance that routes incoming requests to handlers based on the URL
Let's look at the helloworld.py we used in previous chapter (Google webapp2 - Hello World!).
import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.write('Hello, World!') application = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True)
Google App doc explains about What webapp2 Does:
"This code defines one request handler, MainPage, mapped to the root URL (/). When webapp2 receives an HTTP GET request to the URL /, it instantiates the MainPage class and calls the instance's get method. Inside the method, information about the request is available using self.request. Typically, the method sets properties on self.response to prepare the response, then exits. webapp2 sends a response based on the final state of the MainPage instance."
"The application itself is represented by a webapp2.WSGIApplication instance. The parameter debug=true passed to its constructor tells webapp2 to print stack traces to the browser output if a handler encounters an error or raises an uncaught exception. You may wish to remove this option from the final version of your application."
Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization