Well you can add the view multiple times with different renderers if you can determine what you want to do via predicates. For example
@view_config(route_name='route', xhr=True, renderer='json')
@view_config(route_name='route', renderer='r.mako')
@view_config(route_name='route', request_param='fmt=json', renderer='json')
def r(request):
# ...
Or you can just override the renderer manually via request.override_renderer = 'b.mako'
:
http://docs.pylonsproject.org/projects/pyramid/en/1.3-branch/narr/renderers.html#overriding-a-renderer-at-runtime
Or you can just explicitly render the response via the render
and render_to_response
methods from within the view, as the renderer
argument is ignored if you return a Response
object from the view.
Note that the xhr
predicate in the first example should be sufficient to check for an ajax request. Note also that you don't have to use the same view for both if you don't want to, just depends.