webapp
어플리케이션은 세가지 파트로 구성되어있다:
- 요구를 처리하고 반응하는 하나 혹은 그 이상의
RequestHandler
클래스 - URL 기반의 핸들러로 들어온 요구를 라우트하는
WSGIApplication
인스턴스 - CGI adaptor를 사용하여
WSGIApplication을 실행하는 메인 루틴
webapp
어플리케이션에 어울리게 기존의 helloworld.py 를 수정하여 다음과 같이 다시 코딩해보자:
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, webapp World!')
application = webapp.WSGIApplication(
[('/', MainPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()
run_wsgi_app(application)
Runs a WSGI application in App Engine's CGI environment. This is comparable to using a WSGI-to-CGI adaptor such as the one provided by the wsgiref
module of the Python standard library, but has several advantages: run_wsgi_app() automatically detects whether the application is running in the development server, and if so outputs errors to the browser in addition to the log. run_wsgi_app() also allows App Engine to send data output by the handler prior to the error, which wsgiref.handlers.CGIHandler
doesn't do.
Arguments:
- application
- A WSGI application object, such as webapp.WSGIApplication.
The WSGIApplication Class
The google.appengine.ext.webapp
package provides the following classes:
- class WSGIApplication(url_mapping, debug=False)
A WSGI-compatible application that maps URL paths to RequestHandler classes. An App Engine CGI script creates a WSGIApplication object, then runs it using a WSGI CGI handler such as run_wsgi_app().
Arguments:
- url_mapping
- A mapping of URL paths to request handlers, as a list of tuples where each tuple is a path-to-handler mapping. The first element of the tuple specifies the URL path as a string. The second element of the tuple is the constructor of a request handler class, a subclass of RequestHandler.
- debug
- If
True
, the application runs in "debug mode." Primarily, this means that the request handler's handle_exception() method is called with debug_mode=True
when the handler raises an exception, which prints debugging information to the web browser.
출처
- http://code.google.com/appengine/docs/python/gettingstarted/usingwebapp.html
- http://code.google.com/appengine/docs/python/tools/webapp/utilmodule.html#run_wsgi_app
- http://code.google.com/appengine/docs/python/tools/webapp/wsgiapplicationclass.html
댓글 없음:
댓글 쓰기