Personal tools
Navigation
About this blog
なごすいぶろぐ。「すべてはなごすいのために」。
Categories
COREBlog2 (29)
Zope (59)
Linux (26)
Misc (47)
Nagosui (11)
ReadingCOREBlog (7)
Plone (74)
Python (17)
Turbogears (18)
COREBlog1 (30)
moblog (5)
Django (12)
Recent entries
ALAにJeffさんの記事が。 nyusuke 2007-06-14
WebデザイナーのためのDjangoはじめの一歩 nyusuke 2007-05-29
東海Python Workshop 01終了 nyusuke 2007-05-27
東海Python Workshop 01が開催されます nyusuke 2007-05-13
管理画面からみるPlone3.0ベータ(後半) nyusuke 2007-05-03
Recent comments
Re:WebデザイナーのためのDjangoはじめの一歩 nyusuke 2007-06-01
Re:WebデザイナーのためのDjangoはじめの一歩 pateo 2007-05-31
Re:東海Python Workshop 01終了 nyusuke 2007-05-31
Re:東海Python Workshop 01終了 kfuruhata 2007-05-30
Re:管理画面からみるPlone3.0ベータ(前半) nyusuke 2007-05-03
Recent trackbacks
Plone Captcha 1.0.2 と Plone Captchas 1.0 takalog 2007-01-13
plone 2.5.2-rc1 にアップグレード takalog 2007-01-05
Vine Linux 4.0 にアップグレード(その1) takalog 2006-11-26
オハイオ州日本語サイトを手かけ始めた ロバートのブログ 2006-08-14
TurboGears関連記事 Twisted Mind in TurboGears 2006-08-06
Recent Changes
All recent changes…
Amazon Items






Adsense
Document Actions

Turbogearsのプロジェクトを起動する

by nyusuke posted at 2006-07-28 07:00 last modified 2006-08-06 17:38
アプリが起動した

今日も元気に(ホントは眠いけど…)Turbogears!と思ってフォルダを開いてみたら、いつの間にか「locales」というフォルダが増えていました。おそらく前回tg-admin i18nを実行したためだと思います(すぐCtr+Cしたけど…)。

localesフォルダが増えてた

まぁそれはどうでもよいとして、前回まででとりあえずプロジェクトのひな形ができあがったわけで、この次は何をしたらいいのでしょうか。よくわからないのでネット上を徘徊してみると、start-PROJECT.pyスクリプトを実行すれば(特に何もいじらずとも)アプリケーションが起動するみたいです。ということで

python start-junksnack.py

としてみました。するとlocalhost:8080で画面が確認できました。しかもご丁寧にもこの後の開発手順が書いてある(・∀・)

1.  Edit your project's model.py to create SQLObjects representing the data you're working with
2. Edit your dev.cfg file to point to the database you'll be using
3. Run "tg-admin sql create" to create the tables in the database
4. Edit controllers.py to add the functionality to your webapp
5. Change the master.kid template to have the headers and footers for your application.
6. Change welcome.kid (this template) or create a new one to display your data
7. Repeat steps 4-6 until done.
8. Profit!

さっそく次へ進みたいと思います。というのはウソで、ちょっと足を止めてstart-junksnack.pyを見てみます。だっていきなり手順1がちょっと難しそうなんだもん。

start-junksnack.pyの冒頭部はいろんなモジュールのインポートです。

#!C:\Python24\python.exe
import pkg_resources
pkg_resources.require("TurboGears")

import turbogears
import cherrypy
cherrypy.lowercase_api = True

from os.path import *
import sys

よくわからなかったのがpkg_resourcesとcherrypy.lowercase_apiですが、pkg_resourcesというのはegg関係の人らしく、Turbogearsがインストールしてないとダメだよということのようです。まぁ、見た感じそのままですね…。

またcherrypy.lowercase_apiは、CherryPyのサイトに何か書いてありました。CherryPyのAPIはCamelCaseで書かれていたのですが、それをlowercase_with_underscoresで書くようになった、と。しかも何かちょっとだけ起動が速くなるようですね(・∀・)

There's a new "cherrypy.lowercase_api" flag, so that users can say "I'm using the new lowercase API" and get a (small) speed boost from it.

start-junksnack.pyの残りの部分は以下の通り:

# first look on the command line for a desired config file,
# if it's not on the command line, then
# look for setup.py in this directory. If it's not there, this script is
# probably installed
if len(sys.argv) > 1:
    turbogears.update_config(configfile=sys.argv[1],
        modulename="junksnack.config")
elif exists(join(dirname(__file__), "setup.py")):
    turbogears.update_config(configfile="dev.cfg",
        modulename="junksnack.config")
else:
    turbogears.update_config(configfile="prod.cfg",
        modulename="junksnack.config")

from junksnack.controllers import Root

turbogears.start_server(Root())

なるほど、ほんとは設定ファイルを指定できるわけですか。

最初にsys.argvを見て、設定ファイルが引数として指定されていればそれを使うということですね。で、設定ファイルが指定されていないときは、setup.pyがあればdev.cfgを、そうでなければprod.cfgを使うわけですか。名前からすると、dev.cfgは開発用の設定ファイル、prod.cfgは本番用の設定ファイルという認識でよいのですかな…?

そのあとのcontrollersとかstart_serverとかはsite-packagesの中のTurbogears-VERSION.eggフォルダの中のファイルの中にあったけれど、難しそうだったので深追いするのは止めました(*´Д`)頭がこんがらがった~。あー、ホントに頭悪いなー。困った困った。

あー、朝だ。1.5hほど寝ておこう。おやすみなさぃ。

Category(s)
Turbogears Turbogears
The URL to Trackback this entry is:
http://nagosui.org/Nagosui/COREBlog2/start-project/tbping

TurboGears関連記事

Posted by Twisted Mind in TurboGears at 2006-08-06 17:38
Turbogearsのプロジェクトを作る — nagosui.org http://nagosui.org/Nagosui/COREBlog2/create-project Turbogearsのプロジェクトを起動する — nagosui.org http://nagosui.org/Nagosui/COREBlog2/start-project 素晴らしく丁寧に説明されております。 素晴らしい。 間違ってトラックバックを送っておこう。
Add comment

You can add a comment by filling out the form below. Plain text formatting.

(Required)
(Required)
(Required)
(Required)
Enter the word