-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrypyramid.py
More file actions
28 lines (20 loc) · 855 Bytes
/
trypyramid.py
File metadata and controls
28 lines (20 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from wsgiref.simple_server import make_server
from pyramid.config import Configurator
from pyramid.response import Response
def hello(request):
return Response('Hello world!')
def hello_dyn(request):
return Response('Hello %(name)s!' % request.matchdict)
def show_request(request):
return Response('<html><body><pre>%s</pre></body></html>' % request.as_text())
if __name__ == '__main__':
config = Configurator()
config.add_route('hello_world', '/')
config.add_view(hello, route_name='hello_world')
config.add_route('hello_world_dyn', '/hello/{name}')
config.add_view(hello_dyn, route_name='hello_world_dyn')
config.add_route('request', '/request')
config.add_view(show_request, route_name='request')
app = config.make_wsgi_app()
server = make_server('0.0.0.0', 8080, app)
server.serve_forever()