开发者

appending flash message in json , web2py

开发者 https://www.devze.com 2023-03-19 06:14 出处:网络
I am querying web2py using json. I want to append the flash message in the json object th开发者_StackOverflow社区at is returned. By default web2py makes json object only of variables used in the page.

I am querying web2py using json. I want to append the flash message in the json object th开发者_StackOverflow社区at is returned. By default web2py makes json object only of variables used in the page. One way to go about this is manually append flash message in all the dict objects that i return which may not be feasible all the time.

I am using simple dictionary rendered json.

thanks for the response in advance


UPDATED:

You could use the generic.json view to return your JSON, and add code to that view to include the flash message in the returned JSON:

{{from gluon.serializers import json}}
{{response._vars.update(flash=response.flash)}}
{{=XML(json(response._vars))}}

Note, generic views are now disabled by default, so you'll have to explicitly enable the generic JSON view via response.generic_patterns=['json'] (ideally, you should only enable the generic view for requests that require it -- if it is available for requests not intended to return JSON, it can be used to expose data returned to the view that was not meant to be exposed). You can also explicitly specify generic.json (or any name you would like to give it) via response.view='generic.json'.

0

精彩评论

暂无评论...
验证码 换一张
取 消