On 8/21/06, Thomas <[EMAIL PROTECTED]> wrote:
> but I am sure there must be a simpler way of retrieving the same
> information site wide and on each page where needed? Below is an
> example extract from my views.py file...see what I mean? I seem to be
> calling  / using the "c = Context({" too many times. Is this the best
> way of doing things? An example would be something like displaying the
> First name and Last name of a user that is logged in accross all my
> pages. Take a look below:

Well, first of all the repeated template loads and context
instantiations can be avoided by using the 'render_to_response'
function, which is documented in the official tutorial[1]

And if you've got certain variables which need to appear in the
context of *every* page, you probably want to write a context
processor function[2] and use RequestContext instead of Context (you
can still use render_to_response -- just add the extra argument
'context_instance=RequestContext(request)' to it).

The built-in context processor django.core.context_processors.auth is
enabled by default for every RequestContext, and will add the current
user to the template context for you automatically, so that's one of
your variables taken care of already :)

[1] 
http://www.djangoproject.com/documentation/tutorial3/#a-shortcut-render-to-response
[2] 
http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext


-- 
"May the forces of evil become confused on the way to your house."
  -- George Carlin

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

Reply via email to