if you need to return 2 dicts :

*@view_config(route_name="special_view', renderer='json')*
*def special_view(request)*
*        return {'viewA': **ViewOne(request).view_a()['viewA']**, 'viewB': *
*ViewTwo(request).**view_b()**['viewA']**}*

This will throw KeyError exception if returned dicts don't contain key 
'viewA'.


if you need to overwrite dict from ViewOne() with dict from ViewTwo():
ret_dict = *ViewOne(request).view_a()['viewA']*
ret_dict.update(*ViewTwo(request).**view_b()**['viewA']*)
return {'viewA' : ret-dict}

On Friday, February 28, 2014 11:15:57 AM UTC+1, Chung WONG wrote:
>
> Hi all,
>
> Say If there are two views as below:
>
> *class ViewOne(object):*
> *    def __init__(self, request):*
> *        self.request=request*
>
> *    @view_config(route_name='a', renderer='json')*
> *    def view_a(self):*
> *        return {'viewA: some_dict}*
>
> *class ViewTwo(object):*
> *    def __init__(self, request):*
> *        self.request=request*
>
> *    @view_config(route_name='b', renderer='json')*
> *    def view_b(self):*
> *        return {'viewA: some_dict_too}*
>
>
> both of them return response as json. What is the best way to combine both 
> responses as a single response in another views?
> For example:
>
>
> *@view_config(route_name="special_view', renderer='json')*
> *def special_view(request)*
> *        return {'viewA: some_dict, 'viewB': some_dict_too}*
>
>
> I tried using subrequest, however, I couldn't find a way to merge the two 
> responses returned by the two views.
>
> Thanks in advance.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to