Just take note that the regular json encoder won't be able to encode query
results, dates, mongodb objects and a few other things. While the
tg.json_encode function is the same exact function used by @expose('json')


On Fri, Jul 29, 2016 at 12:43 AM, Uwe <[email protected]> wrote:

> On Thursday, July 28, 2016 2:24:44 PM PDT Alessandro Molina wrote:
>
> On Wed, Jul 27, 2016 at 6:08 PM, Uwe <[email protected]> wrote:
>
> Alessandro, I should have mentioned that I did try that config setting.
> But guess what:
>
> The response has to be a dict or a string or you see other errors pop up
> because code down the chain expects a dict.
>
> Ah yeah, sorry, I through you were blocked on the JSON encoder. Yes, by
> design TurboGears actions can only return strings or dicts, in all cases.
>
> What you want to achieve can be done by returning the result of
> tg.json_encode:
>
> @expose('json') def action(self):
>
> return tg.json_encode([1,2,3])
>
> That will use the turbogears json encoder to create the json and if you
> provided the json.allow_lists = True option it will properly send the
> encoded array.
>
> Thanks! I have set the allow_lists config option which is probably why
> using the regular json module works just the same as your solution.
>
> Uwe
>

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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 https://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.

Reply via email to