Detailed description enables django applications with different ports on the same server to be opened in the same browser

Source: Internet
Author: User
This article mainly introduces how to enable django applications with different ports on the same server to be opened in the same browser. if we have two django applications site1 and site2 running on different ports of the same server at the same time, at the same time, we log on to different tabs in the same browser. In this case, when we log on to site2, the user logged on to site1 will be kicked down.

Why is this happening? This is related to the django session framework. here is a brief introduction: when we visit a django website for the first time, django will generate a session to save some information about the current session. At the same time, a hash value session_key is generated and a cookie is generated and sent to the client. the cookie name is set according to SESSION_COOKIE_NAME in setting. the default value is "sessionid" (highlighted ). In this way, the next request for session_key will be sent to the server following the cookie. Server searches for the corresponding session object based on session_key to obtain information about the current session, including logon information.

So there is only one truth in the above situation (Ke Nan pushes glasses face ):

  1. Log on to site1 to get a cookie named sessionid, which stores session_key1.

  2. When we log on to site2, we will update the cookie named sessionid. now its value is session_key2 (the cookie stored in the browser is based on ip rather than Port, so the cookie with the same name will be updated ).

  3. Therefore, when you use the new session_key to access site1, you will not be able to obtain the original logon information. you need to log on again.

So how can we solve this problem? after understanding the above mechanism, you only need to set SESSION_COOKIE_NAME in setting. For example, you can set SESSION_COOKIE_NAME = 'site2' in site2, and use the default value in site1. You can also set site1 and site2 at the same time.

For more details, you can open relevant articles in the same browser for django applications with different ports on the same server. please follow the PHP Chinese network!

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.