0

I want to have multiple django projects but using just one user database to login and have that instance (request.user)? I am using PostgreSQL.

I mean when I access to one app of Django still has the same cookie for login or user another app.

SurvivalMachine
  • 7,946
  • 15
  • 57
  • 87
  • It depends, for example if they're on a sub-domain then you can set **session** for your whole domain to make it available in all your sub-domains. See [here](https://stackoverflow.com/questions/3742675/sharing-django-sessions-on-specific-subdomains) – Amin Alaee Aug 09 '17 at 06:05

1 Answers1

1

Possible and here are your two options

  1. You need to share DB between your apps and configure Cookie

    a. To share db for USERS model https://docs.djangoproject.com/en/dev/topics/db/multi-db/

    b. Update settings

    https://docs.djangoproject.com/en/1.11/ref/settings/#std:setting-SESSION_COOKIE_DOMAIN will give you access to cross-domain cookies

    SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" 
    SESSION_COOKIE_NAME = 'your_cookie_name'
    SESSION_COOKIE_DOMAIN = '.yoursite.com'
    SECRET_KEY = "Share same key(this key) between your apps"
    

    SECRET_KEY should be same in both app's settings.py

  2. Try to implement Django openid, something like FB oauth login / Google oauth login

    Here is Django OIDC: http://django-oidc-provider.readthedocs.io/en/v0.5.x/

naren
  • 14,611
  • 5
  • 38
  • 45
  • so when i implement django openid i can share the login between django projects? i asked this because i have already 3 projects with different order of ids user (repeated) on each project, but i want to create a "master" database then with that database if an user logged in on app and change to another man the other project detect that the user has already logged in – Cesar Becerra Aug 09 '17 at 13:48
  • Yes, you can share login, but the user needs to authorize the login, something like how you login to Netflix using Facebook. – naren Aug 10 '17 at 06:35
  • i will try share a database with users only through all my django projects, thanks @naren – Cesar Becerra Aug 10 '17 at 17:19