Sessions with different expiry dates

3 views
Skip to first unread message

ggates03

unread,
Feb 24, 2009, 2:36:17 PM2/24/09
to Django users
Is there any way to have multiple sessions for one browser? Basically
I have a need for different cookie values to expire at different
times. There are some values I want to expire with the browser
session, however there are other values I would like to last longer,
for example a last visited date.

George Gates

Malcolm Tredinnick

unread,
Feb 24, 2009, 9:35:06 PM2/24/09
to django...@googlegroups.com

Multiple sessions? No, since the Django sessions framework is
implemented via a single cookie on the client side.

Multiple cookies, however, is easy. Just set the cookie details in the
HttpReponse yourself, giving them whatever names and expiry times you
like. See the django.contrib.sessions.* code for an example of how to do
this if you like.

Hmm ... just occurred to me: you could combine both solutions. Implement
the whole multiple cookies stuff and make it into a session backend.
Django supports custom / third-party session backends (it's pluggable),
so once you get this working by hand, you could make it work
transparently via the session mechanism with a bit of extra work.

Regards,
Malcolm


ggates03

unread,
Feb 26, 2009, 10:45:50 AM2/26/09
to Django users
Thank you, that set me on the right track.

On Feb 24, 9:35 pm, Malcolm Tredinnick <malc...@pointy-stick.com>
wrote:
> On Tue, 2009-02-24 at 11:36 -0800, ggates03 wrote:
> > Is there any way to have multiple sessions for one browser?
> >  Basically
> > I have a need for different cookie values to expire at different
> > times.  There are some values I want to expire with the browser
> >session, however there are other values I would like to last longer,
> > for example a last visited date.
>
> Multiple sessions? No, since the Django sessions framework is
> implemented via a single cookie on the client side.
>
> Multiple cookies, however, is easy. Just set the cookie details in the
> HttpReponse yourself, giving them whatever names and expiry times you
> like. See the django.contrib.sessions.* code for an example of how to do
> this if you like.
>
> Hmm ... just occurred to me: you could combine both solutions. Implement
> the whole multiple cookies stuff and make it into asessionbackend.
> Django supports custom / third-partysessionbackends (it's pluggable),
> so once you get this working by hand, you could make it work
> transparently via thesessionmechanism with a bit of extra work.
>
> Regards,
> Malcolm
Reply all
Reply to author
Forward
0 new messages