Re: [tornado] Async functions in tornado templates

91 views
Skip to first unread message

Didip Kerabat

unread,
Oct 5, 2012, 12:01:06 PM10/5/12
to python-...@googlegroups.com
Isn't it better to fetch all your values in RequestHandler layer? And then you can potentially cache the result of your async calls without cluttering your templates.

My 2 cents.

- Didip -



On Oct 5, 2012, at 12:00 AM, Alex wrote:

Hello. Is there any way to use async (tornado.gen) functions in templates?

For example, it is possible:
def add(x, y):
   return x + y

### The template
{{ add(1, 2) }}
But what about using AsyncHTTPClient in the callable function? It is useful for rendering some information from API.
The only way is to override tornado.template._parse function and implement own parsing logic using tornado.gen?
Could you please give some workarounds? May be I'm missing smth...


Ben Darnell

unread,
Oct 6, 2012, 12:00:53 AM10/6/12
to python-...@googlegroups.com
I agree - Tornado's templates are very permissive in terms of allowing
logic in the template, but allowing asynchronous operation seems like
it's taking things too far.

There's a pull request to allow asynchronous templates
(https://github.com/facebook/tornado/pull/553), although it doesn't
integrate with the (synchronous) interfaces that are built on
templates (like UIModule and RequestHandler.render), and some template
tags won't work with it ({% apply %} for one).

-Ben
Reply all
Reply to author
Forward
0 new messages