| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Pyramid

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

Pyramid

Python | Django |

導入

  • Python のパッケージ管理 setuptools を導入しておく

VirtualEnvを利用してPythonの仮想環境を作成

インストール
  1. c:\easy_install virtualenv
ワークスペースの作成
  1. c:\work\python>virtualenv --no-site-package env
  2. New python executable in env\Scripts\python.exe
  3. Installing setuptools................done.
  4. Installing pip...................done.
仮想環境の実行
  1. c:\work\python\env>cd Scripts
  2.  
  3. c:\work\python\env\Scripts>activate
  4. (env) c:\work\python\env\Scripts>

Pyramidのインストール

ワークスペースに移動
  1. (env) c:\work\python\env\Scripts>cd ..
Pyramidのインストール
  1. (env) c:\work\python\env>easy_install pyramid
  2. Searching for pyramid
  3. Reading http://pypi.python.org/simple/pyramid/
  4. Reading http://docs.pylonshq.com
  5.  

Hello World

  • c:\work\python\hello_world.py
  1. from wsgiref.simple_server import make_server
  2. from pyramid.config import Configurator
  3. from pyramid.response import Response
  4.  
  5.  
  6. def hello_world(request):
  7. return Response('Hello %(name)s!' % request.matchdict)
  8.  
  9. if __name__ == '__main__':
  10. config = Configurator()
  11. config.add_route('hello', '/hello/{name}')
  12. config.add_view(hello_world, route_name='hello')
  13. app = config.make_wsgi_app()
  14. server = make_server('0.0.0.0', 8080, app)
  15. server.serve_forever()

実行

  1. (env) c:\work\python>python hello_world.py

1020 pyramid 01.jpg