I have read through various renderers or overriding the renderer , but I wonder the best way to deal with this pattern.
Right now, in my opinion, I am returning a set of elements to the template:
@view_config( route_name = 'name', permission = 'perm', renderer = 'r.mako' ) def r( request ): items = get_items() return { 'items': items }
Now I want the ajax version to simply display a subset as well as some data. My current working code is:
@view_config( route_name = 'name', permission = 'perm', renderer = 'r.mako' ) def r( request ): items = get_items() if ajax: return Response( to_json( { 'data1': 1, 'data2': 2, 'data3': 3, 'html': renderers.render( 'shortr.mako', { 'items': items }, request ) } ) return { 'items': items }
I assume that specifically I am wondering if there is a cleaner way to override the renderer and then wrap it with something, without explicitly invoking the rendering and ensuring that I get the right or request as a parameter. thanks
Timmy source share