is really just boilerplate, which is better done as a decorator. Count how many times the word 'hello' appears in that snippet above. And this is just for a hello world program. Once you start on a real app, that's only going to multiply.
In a more traditional Pyramid app it would be done more like:
from pyramid.view import view_config
from pyramid.response import Response
from paste.httpserver import serve
@view_config(route_name='hello')
def hello_world(request):
return Response('Hello %(person)s' % request.matchdict)
if __name__ == '__main__':
config = Configurator()
config.add_route('hello', '/hello/{person}')
config.scan()
serve(config.make_wsgi_app())
The config.scan() bit causes the @view_config decorators to be picked up. So we do have some decorators, although they don't populate an external registry (by design).
The rationale for putting the route ordering in imperative code instead of using decorator declaration order is in the document I linked. I'm not particularly interested in crippling Pyramid for larger apps to race to the bottom of the LOC count. It's succinct enough and works for truly large apps too.
The ordering of your patterns matters, so that is done at config time. However it's very common to want to have unrelated code executed depending on the type of request to a URL. Pyramid will do this lookup for you, rather than polluting a gigantic view function with multiple code-paths for distinct functionality.
anthonyb|14 years ago
mcdonc|14 years ago
The rationale for putting the route ordering in imperative code instead of using decorator declaration order is in the document I linked. I'm not particularly interested in crippling Pyramid for larger apps to race to the bottom of the LOC count. It's succinct enough and works for truly large apps too.
mmerickel|14 years ago