On Jan 3, 2008 2:33 PM, annacoder <[EMAIL PROTECTED]> wrote: > > I understand *how* it is done. > > But, my question was not related to the how part.
Here's a quick rundown of the "why". Templates aren't triggered by HTTP requests like views are. Instead, they're rendered inside views, which *are* triggered by HTTP requests. Since the request triggers the view, it makes sense for the view to receive the request object. Since templates are rendered by views, it makes sense for templates to receive whatever the view sends them, and nothing more. This is a design decision for at least a few reasons. 1) It allows templates to be more easily used outside of views, for things like rendering reports about the content in the database or anything else you might imagine. 2) It provides a clean separation of concerns. Views deal with requests and responses, templates deal with variables and output formatting. And since the view's the one "in charge" of the relationship, it should be up to the view to decide what the template gets access to. 3) The request would have to come from somewhere. Either you provide it to the template explicitly (usually via RequestContext) or the template code has to reach into Python's internal runtime data to magically retrieve the request from the view. This process is very bad because it: * isn't very fast * is very very ugly * is far from foolproof * makes the view feel like Rob Lowe at the end of Wayne's World (if you haven't seen it, trust me, it's not a good thing) 4) If you're more philosophical, this is also covered very clearly in Tim Peter's Zen of Python: "Explicit is better than implicit." You explicitly send the request to the template, so it's a Good Thing. -Gul --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---