기본 구조는 세 부분으로 구성되어 있다.

1. RequestHandler 클래스로 하나이상의 요청과 답변 처리

2. WSGIApplication 인스턴스로 URL을 통해 들어오는 요청을 처리

3. CGI Adapter로 WSGIApplication 메인루틴 실행

 

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!')
    #여기가 함수의 종료점(파이썬은 띄어쓰기로 구분)
 
#'/' 로 들어 오는 요청을 MainPage 클래스와 연결
application = webapp.WSGIApplication(
                                     [('/', MainPage)],
                                     debug=True)

def main(): #메인루틴 실행 함수
  run_wsgi_app(application) #위에서 선언한 application을 실행함.

if __name__ == "__main__":
  main()
 
결과:
 

[관련글]
Hello, World! - Getting Started: Python - Google App Engine 
파이썬 구글 엡엔진 이클립스 개발환경 
Google App Engine 

+ Recent posts