Custom Search

Wednesday, January 2, 2013

Creating Your First Pyramid Application example

from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response


def hello_world(request):
    print "===request.matchdict===", request.matchdict ,"\n"
    return Response('Hello %(name)s!' % request.matchdict)

if __name__ == '__main__':
    """In browser, type http://127.0.0.1:8080/hello/saju
       Here string "saju" will map to "name" and
       get in view via dictionary request.matchdict.
       eg:{'name': u'saju'}.
    """   
    config = Configurator()
    config.add_route('hello', '/hello/{name}')
    config.add_view(hello_world, route_name='hello')
    app = config.make_wsgi_app()
    server = make_server('0.0.0.0', 8080, app)
    print "===Server Running==="
    server.serve_forever()
    print "===Server Stopped==="


OutPut
#######


In Terminal
*************
saju@saju-desktop:~/pyra_env$ python test.py
===Server Running===
===request.matchdict=== {'name': u'saju'}

In Browser
************

Hello saju!

No comments:

Post a Comment