Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Pyramid

on

  • 2,940 views

 

Statistics

Views

Total Views
2,940
Views on SlideShare
2,753
Embed Views
187

Actions

Likes
0
Downloads
13
Comments
0

5 Embeds 187

http://tal2tot4uenli8d3lphbjvrrl237cfes-a-sites-opensocial.googleusercontent.com 111
http://www.python.rk.edu.pl 63
http://a0.twimg.com 9
https://duckduckgo.com 3
https://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Pyramid Pyramid Presentation Transcript

    • Pyramid Python hack-a-thon 2010.11 aodag
    • 自己紹介 小田切篤 @aodag 株式会社ビープラウドに勤めてます。 ちょっと前まで名古屋にいました http://aodag.posterous.com/ http://blog.aodag.jp/ http://facebook.com/aodag
    • Pyramid Webアプリケーションフレームワーク 元は、repoze.bfg 2010/11/5 repozeプロジェクトからpylonsプロジェクトに移動 このときにPyramidに名称変更 Pyramidの最新バージョン 1.0a3 repoze.bfgの最終バージョン1.3
    • インストール $ virtualenv --no-site-packages --distribute newproject $ cd newproject $ bin/pip install pyramid
    • お約束のHello, World from paste.httpserver import serve from pyramid.configuration import Configurator from pyramid.response import Response def hello_world(context, request): return Response('Hello world!') if __name__ == '__main__': config = Configurator() config.begin() config.add_view(hello_world) config.end() app = config.make_wsgi_app() serve(app, host='0.0.0.0')
    • ちょっと追加 def details_view(context, request): return Reponse('THis is detail') ..... config = Configure(root_factory=get_root) config.add_view(details_view, name='details') .....
    • 簡単な流れ / hello_world(root_object, request) /hoge/foo/bar hello_world(root_object['hoge']['foo']['bar'], request) /hoge/foo/bar/details details_view(root_object['hoge']['foo']['bar'],request)
    • モデル定義 from persistent import Persistent class Document(Persistent): def __init__(self, title, contents): self.title = title self.contents = contents
    • データ追加 @view_config(name="add_document"): def add_document(context, request): params = request.params doc = Document(title=params['title'], contents=params['contents']) context[name] = doc return HTTPFound(location=model_url(doc, request))
    • モデル表示 @view_config(for_=Document, renderer="template/document.pt") def document_view(context, request): return dict(title=context.title, contents=context.contents)
    • テンプレート <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <h1>${title}</h1> <p>${contents}</p> </body> </html>
    • テスト(1) def setup(): global config, context config = Configure() config.begin() context = Folder() def teardown(): config.end()
    • テスト(2) @nose.with_setup(setup, teardown) def test_hello(): import newproject.views.add_document req = DummyRequest() req.params = {"name":"first-document", "title":u"テスト", "contents":u"内容"} info = add_document(context, req.params) assert info.location == 'http://example.com/first-document/' assert context['first-document'] is not None doc = context['first-document'] assert doc.title == u'テスト'
    • テストを走らせる noseを使う $ bin/pip install nose $ bin/noserunner newproject
    • 情報源 http://docs.pylonshq.com/ http://pypi.python.org/pypi/pyramid/ http://docs.repoze.org/bfg/
    • コミュニティ 日本のコミュニティ Pylons-ja ちょっと開店休業状態 Google Group http://groups.google.com/group/pylons-ja Facebook Group http://www.facebook.com/home.php? sk=group_157480254294440
    • ご清聴 ありがとうございました