GoogleAppEngineLauncher で Hello, world! を webapp フレームワークで - はじめてのGAE その2

前回 につづいて GoogleAppEngine のチュートリアル

手順

  1. helloworld.py を編集
  2. Web サーバを起動し、アクセス
  3. Hello, world!
1. helloworld.py を編集

GoogleAppEngineLauncher.app で新規アプリケーションを作成(File > New Application(cmd + N))した際に出来る main.py の内容が以下の様にチュートリアルのものとほぼ同じだったので、

#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#




import wsgiref.handlers


from google.appengine.ext import webapp


class MainHandler(webapp.RequestHandler):

  def get(self):
    self.response.out.write('Hello world!')


def main():
  application = webapp.WSGIApplication([('/', MainHandler)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)


if __name__ == '__main__':
  main()

これをコピーして編集することにした。

import wsgiref.handlers

from google.appengine.ext import webapp

class MainPage(webapp.RequestHandler):
  def get(self):
    self.response.headers['Content-Type'] = 'text/plain'
    self.response.out.write('Hello, webapp World!')

def main():
  application = webapp.WSGIApplication(
                                       [('/', MainPage)],
                                       debug=True)
  wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
  main()
http://code.google.com/appengine/docs/gettingstarted/usingwebapp.html
2. Web サーバを起動し、アクセス
  1. Control > Run(cmd+R)
  2. Control > Browse(cmd+B)
3.Hello, world!

実際は helloworld.py 中の インデントにスペースとタブを混在させてしまいエラーが沢山表示された。不注意注意

余談

ついでにアップロードしてみようと試みた。

  1. http://appengine.google.com/ へログイン
  2. 携帯電話のSMSを使用してアカウントの認証をするようだ
    1. 国名(japan)、キャリア((jp) Willcome)を選択、電話番語(+81 070xxxxxxxx)を入力して[Send]
    2. エラー
  3. とりあえず保留して(Hello, world! だけだしな)チュートリアルを先へ進めることに決めた