Search code examples
pythondjangosessiondjango-sessionsdjango-users

Allowing Users logged in with multiple accounts at once to the same Django site


I'm creating a widget that gets installed on various different sites and I need distinct users for each site. Problem is, the same person browsing might have 2 different sites open at once that use my widget. This means that I need users to be logged in with multiple accounts simultaneously to the same Django site.

From my understanding, Django usually assumes that only 1 user is logged in per session.

What's the simplest and most effective way to go about this?


Solution

  • I ended up storing the per-site data in the user's session, i.e. session['site_id_1'] = user_obj_1, session['site_id_2'] = user_obj_2, etc...

    Instead of logging in, I just store the user data in the appropriate key. Instead of logging out, I delete the key for the site.