How to set the session expiration time with Django

Source: Internet
Author: User
time-out setting for session

In Settings

session_cookie_age=60*30 30 minutes. Session_expire_at_browser_close False: Session cookies can remain valid in the user's browser. True: The cookie expires if the browser is closed. Session_cookie_domain effective Site Session_cookie_name The name of the session stored in the COOKIE

Session use is relatively simple, in Request.session is a dictionary class. The session is saved in the database.

-------------------------------------------------------

The "Session_cookie_age" and "Session_expire_at_browser_close" in the settings.py are not valid according to the manual and the online method. By looking at the Django source code "middleware.py" We know that these two parameters are only available in settings. Valid only if Session_save_every_request is true. The problem is resolved after setting this variable in settings.py. Session_cookie_age does not take effect if Session_expire_at_browser_close is true from source code. This means that the user can only select one two, when the browser is closed to invalidate the session or timeout.

--------------------------------------------------------------

The following method is not used in settings.

Request.session.set_expiry (value)

You can pass four different values to it:

* If value is an integer, the session will expire after a few seconds (applicable to the entire Django framework, where the entire page will expire when the value is aging).

* If value is a datatime or timedelta,session, it will expire after this time.

* If value is 0, the user closes the browser session will expire.

* if value is none,session it will depend on the global session expiration policy.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.