开发者

Django logout and redirect after inactivity

开发者 https://www.devze.com 2023-03-17 07:13 出处:网络
By setting SESSION_COOKIE_AGE and turning SESSION_SAVE_EVERY_REQUEST, it will log people out after a certain time of inactivity. But is there anyway to r开发者_开发问答edirect after say 5 mins of inac

By setting SESSION_COOKIE_AGE and turning SESSION_SAVE_EVERY_REQUEST, it will log people out after a certain time of inactivity. But is there anyway to r开发者_开发问答edirect after say 5 mins of inactivity?


You can use setTimeout() to trigger an ajax request, and if it responds with a redirect (you have been logged out), then refresh the page. This method is superior to simply refreshing the page every 5 minutes, as that may be a bad user experience.


If you want to redirect without any action from the user, you have to do it in javascript:

setTimeout(function() { window.location.href = 'http://someURL'; }, 5 * 60 * 1000);
0

精彩评论

暂无评论...
验证码 换一张
取 消