Details a Django application that differs from port on the same server can be opened on the same browser

Source: Internet
Author: User
If we have two Django apps site1 and site2 running on different ports of the same server at the same time, we have different tab logins in the same browser. That's when this happens, and when we log in to Site2, we kick the user who's logged on site1.

Why does this happen? This is about the Django session framework, and here's a quick introduction: When we first visit a Django site, Django generates a session to hold some information about the current session. A hash value Session_key is generated and a cookie is generated to send to the client, and the name of the cookie is set according to the Session_cookie_name setting in setting, which defaults to "SessionID" (focus). So the next time you ask Session_key will follow the cookie sent to the server. The server finds the corresponding session object according to Session_key, obtains the current session information, and of course includes the login information.

So the above situation is only one truth (Conan push glasses face):

  1. Our login site1 is to get a cookie called SessionID that stores session_key1 inside.

  2. When we log in to Site2, the cookie called SessionID is updated, and now it has a value of Session_key2 (the browser store cookies are based on IP instead of the port, so the cookie of the same name is updated).

  3. So now with the new Session_key access to Site1 will not get the original login information, we need to re-login.

So how to solve, understand the above mechanism, only need to set session_cookie_name in setting. For example, you can set session_cookie_name = ' Site2 ' in Site2, site1 by default. Of course, you can also set site1 and site2 at the same time.

More details to enable Django apps with different ports on the same server to open related articles on the same browser please follow topic.alibabacloud.com!

  • 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.