async, on-demand lazy rendering for jinja2 possible?

est electronixtar at
Tue Jul 22 04:00:28 CEST 2014

Hi all,

Been reading @igrigorik's posts

I found that flush response as early as possible is crucial for a website

I wanna make Time To First Byte (TTTFB) happen as early as possible with a
Jinja2 site,

Suppose a typical Jinja2 template:

  <title>{{ site_title }}</title>
{% for item in items %}
{% endfor %}

Let's presume site_title is static and known in view function from the
start, I wanna flush everything before <body> to the client as early as
possible, then items was a query from db, it's kinda slower, let's flush
the everything below  <body> later in a second TCP packet.

This looks like impossible at the moment. I searched the Jinja2 docs, the
closest thing I've found is the streaming template API

jinja2.Template('Hello {{ name }}!').stream(name='foo')

Which still requires all variables to be ready before rendering.

Is there a way to stream partial template results with partial template
variables? This would be great help making faster websites. Other template
engine than Jinja2 is welcome as long as it's in python! Thanks in advance!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list