On Thu, 2008-01-03 at 23:10 +0530, venkata subramanian wrote:
> Hi,
>  I had a problem recently.
>  To access the request object in all of my templates.
>  The solution I got surprised me. It involved explicitly passing on
> the request object from the views.
>  (Example, to pass a RequestContext object as a context_instance
> parameter in render_to_response method).
> 
> It surprised me because since request object is available to every
> view, why should the request
> object not be accessible in all templates by default?

Using RequestContext means that all the context processors are run. This
overhead isn't needed in all cases. So Django provides a way to render a
temlpate without the context processors being run (if you use Context())
and with the context processors being run (if you use RequestContext()).
If we always did the second thing, there would be no way to do the first
thing.

It's trivial (not just easy, completely trivial) to write your own
version of render_to_response() if you always want to use
RequestContext. The entire function is two lines long. Of course, you'll
have to pass it the 'request' instance every time, so that it's
initialised correctly, but that's the cost of wanting request-related
stuff.

Yes, we could have the default being the reverse of what it is now, but
the arguments each way are pretty easily balanced. Sometimes you always
want to use RequestContext, sometimes you don't need it at all. So
there's no strong reason to change things when it's so easy to write
your won alternative shortcut.

Regards,
Malcolm

-- 
The early bird may get the worm, but the second mouse gets the cheese. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to