On Jan 4, 7:34 am, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> 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.
>
I agree it is trivial. Also, after looking around, and asking people,
I find that many people do (independently) write that two line
function.
(And I guess, each of those must have done some looking around and
asking people themselves
to come to that two line function).

Example:   http://www.djangosnippets.org/snippets/3/

If it is more like an idiom, then is why is it not a built in shortcut
function?
 1. It will prevent many people from writing that same 2 line code.
 2. While reading the documentation as a newbie, it will become
evidently clear about how one
 can pass the request object to the template.


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

Thanks a lot for your explanation.
Its much clearer to me now.

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