Thanks. I've traced the call stack, the expire_date is affected by SessionBase.*get* ("_session_expiry") , //line 246 in django.contrib.session.backends.base.py and variable `_session_expiry` stored in SessionBase.*_session_cache *, which is set in method SessionBase.*set_expiry*(). //line 259 in django.contrib.session.backends.base.py So I think, there seem exist a customized middleware to handle session expire date by call *set_expire*(). But, in my condition,I need the generated time of session_key, which not stored in django session instance, to calculate the how many seconds left before expire.
在 2016年12月25日星期日 UTC+8下午6:14:27,ludovic coues写道: > > I believe that is the intended behaviour. > > When I use a banking site for example, I don't want to be disconnected > while doing operations 5 minutes after login in. I want the session to > expire when I stop using it. > > Django's session middleware try to solve that use case which is what is > needed 95% of the time. > > As your need is different, you will need something different than what > django provide. Using a custom session store might be the simplest way. > Inherit the one you are using and redefine get_expiry_age to return the > remaining time to live. > > > On 24 Dec 2016 3:46 p.m., "王超" <wcs...@gmail.com <javascript:>> wrote: > > django version is 1.10.4 > > Jsut as the source code shows, session middleware will refresh > expires_time with value time.*time*()+max_age, if the the status code of > response is not 500. > > What was really weird is the variable `*max_age*` , which returned by > function `request.session.*get_expiry_age*()`, always equals to > settings.SESSION_COOKIE_AGE > (positive integer). > > that leads to '*expire_date*' stored in `django_session` table, is > bigger time.*time*(). In the other words, this session item never expired > in back-end db!!! > > what's more, session middleware will send the new `expires` to browser by > call function response.*set_cookie*(), which means this session item > never expired in user's browser too !!! > > > As pratical example, I set settings.SESSION_COOKIE_AGE=30. as long as I > visited my site during `SESSION_COOKIE_AGE` , the cookie with session_key > will persist forever ! > > What I want is that django will force session to expire if time past > `SESSION_COOKIE_AGE` seconds after the moment session_key generated. So how > to config my project ? > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users...@googlegroups.com <javascript:>. > To post to this group, send email to django...@googlegroups.com > <javascript:>. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/030c570c-e085-431c-817f-27eb70e069d7%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/030c570c-e085-431c-817f-27eb70e069d7%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > > > <https://lh3.googleusercontent.com/-hMCM0N7XMew/WGB9ifDd0HI/AAAAAAAAAA0/ygit13mqG0QlVZpnSBJaXIRhta9P3K00gCLcB/s1600/callstack.png> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/b6cd853f-c38d-4409-a75a-8434f5166fd5%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.