Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you explains, SESSION_EXPIRE_AT_BROWSER_CLOSE and SESSION_COOKIE_AGE are not compatible. When you set an expiration date to a cookie, this cookie becomes no browser-length cookie.</p> <p>Then, in order to achieve your desired behavior, you should <strong>set SESSION_EXPIRE_AT_BROWSER_CLOSE as True and control expire timeout by hand</strong>.</p> <p>An elegant way to control by hand expire timeout is:</p> <ol> <li>Create a new <a href="https://docs.djangoproject.com/en/dev/topics/http/middleware/" rel="nofollow noreferrer">custom middleware</a> that control timeout.</li> <li>Modify settings.py to enable your custom middleware (and sessions).</li> </ol> <p>The <strong>timeout custom middleware</strong> can looks like:</p> <pre><code>class timeOutMiddleware(object): def process_request(self, request): if request.user.is_authenticated(): if 'lastRequest' in request.session: elapsedTime = datetime.datetime.now() - \ request.session['lastRequest'] if elapsedTime.seconds &gt; 15*60: del request.session['lastRequest'] logout(request) request.session['lastRequest'] = datetime.datetime.now() else: if 'lastRequest' in request.session: del request.session['lastRequest'] return None </code></pre> <p>Remember enable <a href="https://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow noreferrer">sessions</a> in order to store <code>lastRequest</code>.</p> <p>This solution is wrote and tested be me and is now working in my site. This code has GNU license ;)</p> <p><strong>New on django 1.6</strong> ( ... two years later ... )</p> <p>Datetime and timedelta values are only serializable if you are using the <a href="https://docs.djangoproject.com/en/1.6/topics/http/sessions/#django.contrib.sessions.serializers.PickleSerializer" rel="nofollow noreferrer">PickleSerializer</a>. If not, perhaps easy solution is <a href="https://stackoverflow.com/questions/9744775/how-to-convert-integer-timestamp-to-python-datetime">translate datetime to unix timestamp and back</a>. Be free to post below this translation.</p> <p><strong>Edited</strong></p> <p><a href="https://github.com/yourlabs/django-session-security" rel="nofollow noreferrer">django-session-security</a> app provides a mechanism to logout inactive authenticated users. Take a look.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload