开发者

Change Django Admin Inactivity Timeout

开发者 https://www.devze.com 2023-02-20 09:10 出处:网络
How do you increase the inactivity timeout for Django\'s admin? The default seems incredibly short, and appears to timeout after only a couple minutes, which is very annoying. Not开发者_JAVA技巧e, I\'

How do you increase the inactivity timeout for Django's admin? The default seems incredibly short, and appears to timeout after only a couple minutes, which is very annoying. Not开发者_JAVA技巧e, I'm aware of SESSION_COOKIE_AGE, but I don't want to this change to effect the timeout for the public site.


So, there are two possible causes. The first is that you're losing sessions before their expiration time. SESSION_COOKIE_AGE defaults to 2 weeks. If your session isn't lasting that long, check to make sure your backend isn't using a cache or that the cache is not full (and thus bumping out sessions before their time).

You can force the session to be refreshed on every request by using settings.SESSION_SAVE_EVERY_REQUEST, but this may have performance issues on a busy site.

The other possibility is that you've set SESSION_COOKIE_AGE to something small on purpose but you now want the admin cookies to last longer. There's no way to separate admin session timeouts from normal user timeouts, at least out of the box.

You could also write a middleware that pulls the user out of the request, checks user.is_staff and if so, call request.session.set_expiry() to manually push the expiration time out.


One possible way to accomplish different session timeout settings is to run two instances of your site. One that is only accessible to you (running on localhost:8080 for example) where the admin page is available and has a specific admin_settings.py file for it, and your regular site that is publicly available.

Depending on your server set up this is done easily with Apache and VirtualHosts (I won't go into details about that since you might have a different set up).

Then you can use SSH tunnels to access the admin site running on the localhost of your server.

Another option, if you really don't want your admin site running all the time, is use the manage.py runserver to run an instance of your site, and pass in your admin settings for it (since ideally only you would be accessing this, runserver should be able to handle the traffic):

$ python manage.py runserver --settings=admin_settings localhost:8080

Then access it through an SSH tunnel. If you want to avoid SSH tunnels with this method then you can look into running it publicly, but through stunnel as outlined here

0

精彩评论

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