• Like

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.

Pyramid

  • 2,619 views
Uploaded on

 

More in: Technology , Design
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
2,619
On Slideshare
0
From Embeds
0
Number of Embeds
3

Actions

Shares
Downloads
15
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Pyramid Python hack-a-thon 2010.11 aodag
  • 2. 自己紹介 小田切篤 @aodag 株式会社ビープラウドに勤めてます。 ちょっと前まで名古屋にいました http://aodag.posterous.com/ http://blog.aodag.jp/ http://facebook.com/aodag
  • 3. Pyramid Webアプリケーションフレームワーク 元は、repoze.bfg 2010/11/5 repozeプロジェクトからpylonsプロジェクトに移動 このときにPyramidに名称変更 Pyramidの最新バージョン 1.0a3 repoze.bfgの最終バージョン1.3
  • 4. インストール $ virtualenv --no-site-packages --distribute newproject $ cd newproject $ bin/pip install pyramid
  • 5. お約束の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')
  • 6. ちょっと追加 def details_view(context, request): return Reponse('THis is detail') ..... config = Configure(root_factory=get_root) config.add_view(details_view, name='details') .....
  • 7. 簡単な流れ / 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)
  • 8. モデル定義 from persistent import Persistent class Document(Persistent): def __init__(self, title, contents): self.title = title self.contents = contents
  • 9. データ追加 @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))
  • 10. モデル表示 @view_config(for_=Document, renderer="template/document.pt") def document_view(context, request): return dict(title=context.title, contents=context.contents)
  • 11. テンプレート <html xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <h1>${title}</h1> <p>${contents}</p> </body> </html>
  • 12. テスト(1) def setup(): global config, context config = Configure() config.begin() context = Folder() def teardown(): config.end()
  • 13. テスト(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'テスト'
  • 14. テストを走らせる noseを使う $ bin/pip install nose $ bin/noserunner newproject
  • 15. 情報源 http://docs.pylonshq.com/ http://pypi.python.org/pypi/pyramid/ http://docs.repoze.org/bfg/
  • 16. コミュニティ 日本のコミュニティ Pylons-ja ちょっと開店休業状態 Google Group http://groups.google.com/group/pylons-ja Facebook Group http://www.facebook.com/home.php? sk=group_157480254294440
  • 17. ご清聴 ありがとうございました