Using traversal you'll need to define your own __getitem__ on your
context objects that is capable of discriminating your leaf nodes.

With regards to the SO question, the pyramid way of dealing with this
is much more flexible than the pylons mechanism of an "if" within the
view code. For example you can add a custom view predicate which will
point the view lookup at the same (or different) view with a different
renderer.

def json_fmt(context, request):
    if request.matchdict['ext'] == 'json': return True
    return False

config.add_route('test', '/test')
config.add_route('test_fmt', '/test.{ext}')

config.add_view(route_name='test', view='ms.views.test',
renderer='test.mako')
config.add_view(route_name='test_fmt', view='ms.views.test',
custom_predicates=(json_fmt,), renderer='json')

# ms/views.py
def test(request):
    return {
        'key': 'value',
    }

The returned dictionary will either be passed to the mako template, or
rendered as json depending on which view matched leaving you to focus
on views, letting pyramid handle rendering it for you.

Michael

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to pylons-discuss@googlegroups.com.
To unsubscribe from this group, send email to 
pylons-discuss+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to