On Mon, Jan 9, 2012 at 9:12 AM, Martin Aspeli <[email protected]> wrote:
> Hi, > > I have a resource tree and I'm using traversal and named views. > However, I'd also like to support an /api/ namespace with different > views. So: > > http://example.org/foo would traverse from the root to the resource > foo and render the default (unnamed) view for context=Foo > > but > > http://example.org/api/foo would traverse to foo and render a JSON > representation of foo, using a different view > > I thought I could do this with hybrid routes, e.g: > > config.add_route('api', '/api/*traverse', factory=Root) > > I have a view for context=Root with route_name='api', and it is > rendered, but whenever I try to traverse further, e.g. to '/api/foo', > I get a 404. Moreover, I need some way to distinguish e.g. the unnamed > view on /foo from the unnamed view on /api/foo. > > What is the best way to do this? > > I suspect you're just forgetting the route_name argument to config.add_view (or @view_config) for the views you want to use in the /api/* space. You could also consider using the xhr argument which could allow you to drop the /api/* url space altogether if the json views are being called by something that would set that header. Chris -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
