Fork me on GitHub

2008/07/29

Recent entries from same category

  1. Mumblesを使ったGitHubのGrowl通知アプリケーションを作った。 Hatena
  2. Python2.6にはcursesのバイナリが含まれていないので作る Hatena
  3. 無料ではてなブックマークとdeliciousを同期する方法 Hatena
  4. JSON見づらくないですか? Hatena
  5. pythonで動くtwitter/wassrクライアント「tw2」をWindowsにポーティングした。 Hatena

はてな
まずは素晴らしい出だしだと思う。
google-app-engine-oil - Google Code
Yet another web framework on Google App Engine.

Google App Engine Oil (GAEO) is an open-source web framework running on Google App Engine. It enables the web development on App Engine quick and less configurations.

http://code.google.com/p/google-app-engine-oil/
railsを狙ってるのかなぁ。
これから勉強を始めますが、まずは1分でアプリが作れてしまうという素晴らしい所をご紹介します。

Google App Engine Oil(GAEO)は、上記URLからダウンロード(もしくはsvn trunk取得)して下さい。
"gaeo/bin"にパスが通っている状態から説明します。

アプリケーションテンプレートの作成

gaeoコマンドで生成します。
# gaeo.py hello
The hello project has been created.
これだけでも動きます。試しに
# cd hello
# dev_appserver.py .
...
としてブラウザで"http://localhost:8080/"を開くと
gaeo1
いう画面が起動します。これだけでも実はモデルやディスパッチャやコントローラが生成され、テンプレートが用意されているのでいきなりコーディングが始められます。

コントローラの作成

gaeogenコマンドで生成します。
# gaeogen.py controlller say
Creating application/templates/say/ ...
Creating say.py
これでsayコントローラが生成されます。中身は
from gaeo.controller import BaseController

class SayController(BaseController):
    pass
こんな感じ。あとはこれを少し修正して
#!-*- coding:utf-8 -*-
from gaeo.controller import BaseController

class SayController(BaseController):
  def hello(self):
    self.render(text = 'こんにちわ世界')
とし、"http://localhost:8080/say/hello"にアクセスすると"こんにちわ世界"と表示されます。また"templates/say/"に"hello.html"を以下の様に作成し
こんにちわ {{ word }}
先ほどのsay.pyを以下の様に書き換えます。
#!-*- coding:utf-8 -*-
from gaeo.controller import BaseController

class SayController(BaseController):
  def hello(self):
    self.render(
        template = 'hello',
        values = { 'word' : '世界' }
    )
これでテンプレートを使ったページが出来上がります。

目新しい点

私はここに注目しました。
これまでjsonやxmlをGAEから出力する際には、Content-Typeの設定が必要であったりしましたがGAEOならば上記textやtemplateと同じ様に

#!-*- coding:utf-8 -*-
from gaeo.controller import BaseController

class SayController(BaseController):
  def hello(self):
    self.render(
        xml = '<xml />',
    )
としたり
#!-*- coding:utf-8 -*-
from gaeo.controller import BaseController

class SayController(BaseController):
  def hello(self):
    self.render(
        json = '{ word : "Hello, World!" }',
    )
とするだけで、正しいContent-Typeを返してくれるようになります。

期待したい所

リクエストパラメータself.paramsでパラメータをdictとして受け取れたり、self.sessionで簡単にセッションが扱えたりと開発者にとって扱いやすいフレームワークになっていると思われます。
ただ現状gaeogenコマンドではcontrollerしか生成出来ていません。おそらく今後modelの生成も出来る様になるかと思いますので今後に期待したいです。出来ればrails相当になってくれれば良いですね。

まだちゃんと勉強してないのでこれから色々調べていきます。

blog comments powered by Disqus
WriteBacks

Hello,

It's the GAEO's project owner here. I'm glad to see someone like this project.

In template rendering, you don't have to set the value in render method, just add it to the controller's member variable and it will find the default tempalte. Like this:

def hello(self):
self.word = ''

Please keep on seeing and using the GAEO project. Thanks :-)

Posted by ericsk at 2008/08/04 (Mon) 13:15:03

Re:

Thanks for your great works.
I'll look and try into it! :-)

excerpt:

Posted by mattn at 2008/08/05 (Tue) 14:41:44

TrackBack ping me at
Post a comment

writeback message: Ready to post a comment.