On 12 jan, 10:56, Jo <[email protected]> wrote: > On Jan 12, 10:22 am, bruno desthuilliers > > > > <[email protected]> wrote: > > On 11 jan, 18:46, Jo <[email protected]> wrote: > > > > 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 > > > This has nothing (or very few) to do with inheritance. You'd have the > > same behaviour (ie : first getting all data, then building html, then > > return the response) without using inheritance in your template. > > Yes but template inheritance usually leads to this design.
Nope. This is totally othogonal. The "problem" mostly comes from "push" template systems (template systems that require you to feed them all the relevant data before they can format it). You can have template inheritance in a "pull" template system too. > > > Is there a way to get the best of both > > > worlds? Maybe using generators? Thank you. > > > You can of course pass an iterable to your reponse object (read the > > doc for the HttpResponse object), but then you'll have to organize > > your code very differently, and not necessarily in the most readable > > and maintainable way. > > > As far as I'm concerned, I'd first try to profile and possibly > > optimize the "very long computation" part. > > Yes but you'd have to agree that there is a loss. This is debatable. As far as I'm concerned, I don't see it as an issue. > It would be nice to render data as it comes. > Instead of waiting for all the computation to > finish. If your computation is that long, then you do have another problem IMHO. But anyway: the 'fetch/format/return' scheme has nothing to do with template inheritance, Django's template system can easily be turned into a "pull" template system (using custom tags), and Django's HttpResponse object can take an iterator as content. So you just have to write the appropriate custom tags and hack Django's template system to make it work as an iterator. Then you'll find out that you still have to wait for the_very_long_computation to finish before you can see what it computed. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

