2018-04-17

Quick Tutorial for Pyramidをやってみる

PyramidPython向けWebフレームワーク

Quick Tutorial for Pyramid公式チュートリアル

https://docs.pylonsproject.org/projects/pyramid/en/latest/quick_tutorial/index.html

Prelude: Quick Project Startup with Cookiecutters

$ $VENV/bin/cookiecutter gh:Pylons/pyramid-cookiecutter-starter --checkout 1.9-branch

として、プロンプトの問いに答えるとサンプル的なアプリができる。

ghはgithubか。

引数指定できるテンプレートhttps://github.com/Pylons?q=pyramid-cookiecutter

sqlalchemyを使うものは分かるけど、zodbって何?

アプリは以下のようにして起動する。

$ env/bin/pserve development.ini --reload

このpserveというPythonモジュールアプリ動かしたりする。

01: Single-File Web Applications

超単純なPyramidアプリを作って、WSGIイメージをつかむ。

app.py を書き写して動かしたらHello Worldが動いた。

Analysisの項:
2. Lines 12-14. Use Pyramid's configurator in a context manager to connect view code to a particular URL route.

viewURLの紐付けはconfig.add_routeしてconfig.add_viewする。add_viewしてからadd_routeしても大丈夫だった。

3. Lines 6-8. Implement the view code that generates the response.

viewにはrequestが渡される。requestに色々入ってそう。

4. Lines 15-17. Publish a WSGI app using an HTTP server.

waitressは知らないけど、serveでHTTPサーバ作ってWSGIアプリを公開できるのかな?

Extra creditの項:
1. Why do we do this:
print('Incoming request')

...instead of:

print 'Incoming request'

Python3だから

2. What happens if you return a string of HTML? A sequence of integers?

Inernal Server Errorになった。アプリのほうではValueErrorresponseを返すようにと怒られていた。text/plainとか返すには何かしないとダメっぽい。

3. Put something invalid, such as print xyz, in the view function. Kill your python app.py with ctrl-C and restart, then reload your browser. See the exception in the console?

print(xyz)してみろ、ということかな。1と同じくInernal Server Errorになって、コンソールにはNameErrorが出た。

4. The GI in WSGI stands for "Gateway Interface". What web standard is this modelled after?

CGIかな?

記事への反応(ブックマークコメント)

ログイン ユーザー登録
ようこそ ゲスト さん