Django: Auto logout when Tab is closed (Not browser)
Absolutely nothing to do with Django. It is more related to how browsers treat a cookie.
What happens is that if a cookie doesn't have an expiration date (Expires attribute) or Max-Age, browsers treat them as session cookies. That means a browser will delete that cookie when you exit your browser session i.e. when you close your browser.
And since closing a tab isn't equal to exiting your browser, browsers don't delete a session cookie.



UPDATE: If someone really needs to log the user out on tab close, it can be achieved, well, sort of.
You can set the session cookie's age to a small number, maybe 10 minutes. While the user has the tab opened, every 10 minutes, you refresh the cookie (i.e. make an AJAX requests to get a new cookie).
When the user closes the tab, their session will automatically expire within next 10 minutes.
It's a little complicated setup, but I've seen it implemented on banking sites etc. It's up to you to decide if it's worth it for your site or not.
I've used the following line of code to make my browser log a user out of the Django admin when the browser is closed
SESSION_EXPIRE_AT_BROWSER_CLOSE setting to true
How do I change this and make it in such a way that when the user closes the tab, The user gets logged out?