Hi,

> This has been asked several times, but I am not clear on how people
> are solving it. From what I understand so far, a setting called
> "TEMPLATE_CONTEXT_PROCESSORS" can be tweaked to make this possible.
> However, I'm not seeing a clear way to do that.

A context processor is nothing more than a file. This file has a
function that takes an HttpRequest as an input and that returns a
dictionary with the variables you want to add to every template.

For example, in your case it could be:

add_variable(request):
    the_variable=variable.objects.get(my_user__id=request.user.id)
    return {'user_variable':the_variable}

Now, what you must add to TEMPLATE_CONTEXT_PROCESSORS is the path to
the function you just defined, as
'path.to.context_processor.add_variable'. That means that all
templates will have the {{ user_variable }} variable with the value
the_variable, dynamically assigned for each session.

Of course, you can add as many functions and files to your context_processor.

An example here:
http://svn.guindilla.eu:8000/complutense/eventos/context_processors.py
This adds to all templates the variables I need for a calendar that
appears in every web page of a site and can be dynamically modified.

in my settings.py I had to add:
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
                               "django.core.context_processors.debug",
                               "django.core.context_processors.i18n",

"complutense.eventos.context_processors.calendar")

Hope it helps,

G

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