You can do this with custom context processors (see http://docs.djangoproject.com/en/dev/ref/templates/api/ )
In this case, you must create a new file called context_processors.py at the same level as the settings.py file containing:
def add_session(request): return {'session': request.session}
Then in the settings.py file add:
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth", "django.core.context_processors.debug", "django.core.context_processors.i18n", "django.core.context_processors.media", 'context_processors.add_session',)
Now you can refer to the ['session'] context in your custom tag.
Please note that this will only work for templates created using the assigned RequestContext, as in the following code:
def test(request): return render_to_response('test.html',{}, context_instance=RequestContext(request))
Matthew Christensen Dec 02 '08 at 20:33 2008-12-02 20:33
source share