[python]pyramid 學習1 (hello world)

weixin_34321977發表於2011-09-29

安裝

easy_install pyramid

異常情況:

安裝的時候要求zope.interface 3.80以上

easy_install  zope.interface

 

hello world

 1 from paste.httpserver import serve
2 from pyramid.config import Configurator
3 from pyramid.response import Response
4 from pyramid.view import view_config
5
6 @view_config(name='hello',request_method='GET')
7 def hello(request):
8 return Response("Hello %(name)s!" % request.matchdict)
9
10 if __name__ == '__main__':
11 config = Configurator()
12 config.add_route('hello',"/hello/{name}")
13 config.add_view(hello,route_name='hello')
14 app = config.make_wsgi_app()
15 serve(app,host='0.0.0.0')

 

$ python hello.py
serving on 0.0.0.0:8080 view at http://127.0.0.1:8080

相關文章