Accessing session variables in template with django

5,035 views
Skip to first unread message

Puneet

unread,
May 23, 2009, 1:34:19 AM5/23/09
to Django users
Hi All,

I am facing issue when I am trying to access session variables in
django.

I am setting the session variable something like :

request.session['cityname'] = cityname
c = RequestContext(request, {'current_date': now})
html = t.render(c)
return HttpResponse(html)

And I am trying to access it like :

{{ request.session.cityname }}
and
{{ request.cityname }}

But it does not seem to be working. Any suggestions ?

Thanks,
Puneet


Daniel Roseman

unread,
May 23, 2009, 4:39:06 AM5/23/09
to Django users
You need to enable django.core.context_processors.request in the
CONTEXT_PROCESSORS section settings.py - it's not enabled by default.
See
http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request
--
DR.

Puneet

unread,
May 23, 2009, 11:00:55 AM5/23/09
to Django users
Thanks Daniel,

Its working fine now. :)

On May 23, 1:39 am, Daniel Roseman <roseman.dan...@googlemail.com>
wrote:
> Seehttp://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-c...
> --
> DR.
Reply all
Reply to author
Forward
0 new messages