gae + python で hello world を出力してみた

いまさらですが google app engine を触ってみました。
java とか jruby とか scala とかちょっとめんどそうだったんで、お手軽そうな python にしてみました。
一応出来るところまで python で挑戦してみたいと思います。
python 初めてすけどがんがります(汗)

環境

Mac OS X 10.7.1
gae 1.5.4
python 2.5.5

Google App Engine SDK for Python をダウンロード

http://d.hatena.ne.jp/masayuki14/20110310/1299731540 を参考に


http://code.google.com/intl/ja/appengine/downloads.html から
GoogleAppEngineLauncher-1.5.4.dmg をダウンロードしてアプリケーションフォルダに移動
シンボリックリンク作成しますか?と言われるので yes.


python2.5 は lion には最初から入ってるので python のインストールは必要ないっぽいです。

gae に python2.5 を設定する

http://kishi-r.com/archives/413 を参考に
GoogleAppEngineLauncher を起動して


メニューバー > GoogleAppEngineLauncher > Preferences


Python Path: の項目を「/usr/bin/python2.5」にする。
あと .zshenv か .zshrc に以下を追加。

  • .zshrc
alias gae_server='python2.5 /usr/local/bin/dev_appserver.py'
alias gae_deploy='python2.5 /usr/local/bin/appcfg.py update'

google app engine にプロジェクトを登録する

http://code.google.com/intl/ja/appengine/docs/python/gettingstarted/uploading.html を参考に
プロジェクトを登録します。
僕は適当に「twitter-bobobo」という名前にしました。

hello world のプロジェクトを作成する

mkdir -p ~/work/helloworld
cd ~/work/helloworld
vim helloworld.py
vim app.yaml

  • helloworld.py
print 'Content-Type: text/plain'
print ''
print 'Hello, world!'
application: twitter-bobobo(プロジェクトのApplication Identifier)
version: 1
runtime: python
api_version: 1

handlers:
- url: /.*
  script: helloworld.py

localhost で表示する

cd ~/work
gae_server(= python2.5 /usr/local/bin/dev_appserver.py) helloworld

ブラウザを開いて http://localhost:8080 を開いて「hello world」が表示されてれば成功。

gae にアップロード(デプロイ)する

cd ~/work
gae_deploy(= python2.5 /usr/local/bin/appcfg.py update) helloworld

(自分のApplication Identifier).appspot.com を開くと「hello world」が表示されてれば成功。
ちなみに僕のURLは http://twitter-bobobo.appspot.com/ です。


その他は http://code.google.com/intl/ja/appengine/docs/ を参考にするといいかもしれません。