template inheritance

Diez B. Roggisch deets at nospam.web.de
Sun Jan 11 15:04:11 EST 2009


Alex K schrieb:
> While building a website using template inheritance one usually does
> the following:
> 
> fetch from database
> fetch from some more data from database
> ... << more required computations
> then at the end render the template with the fetched data
> 
> Without template inheritance one usually does the following:
> 
> fetch from database
> render this part of the site with this fetched data
> fetch some more data from the database
> render this other part of the site with the fetched data
> ...
> etc
> 
> The first approach is much more elegant and leads to easier to
> maintain code. However the user will have to wait till the end of the
> fetching (long computations) before any rendering can take place. In
> the second approach however the site loads as we are fetching the data
> which is more convenient to the user.
> 
> Am I correct to assume this? Is there a way to get the best of both
> worlds? Thank you.

I don't think that the question of inheritance or not is really relevant 
here.

It's a matter of how the templating system is written - does it collect 
all the data beforehand, or not, is it potentially using e.g. generators 
and so forth.

And of course how the programmer uses the templating system. does he 
fetch all the data beforehand, or does he use lazy generation approachs 
- again, e.g. generators, or callbacks.

Besides, *usually* the 20-39Kb of a website itself aren't the problem 
I'd say - loading referenced resources is much more of an issue.

And AFAIK the render-mode matters, too. If the site is XHTML-compliant, 
the browser can start the rendering once the HTML is complete - 
otherwise, it might wait until the referenced resources are all loaded 
to calculate the layout.

Diez



More information about the Python-list mailing list