python-3.xdjangodjango-sites

link django user to perticular site in site framework


I've setup Django sites framework in my project, actually, i want to combine Django user to that particular site

What I want to achieve is that when user register from particular site or subsite which register with site framework then that user has to link to that particular site so that we can restrict a user to login to another site with their associate site credential.


Solution

  • In the settings files for your different sites you can specify separate "users" databases, https://docs.djangoproject.com/en/1.10/topics/db/multi-db/

    #in site1 settings.py
    DATABASES = {
        'default': {
            'NAME': 'app_data',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te'
        },
        'users': {
            'NAME': 'user_data_site1',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te'
        }
    }
    
    #in site2 settings.py
    DATABASES = {
        'default': {
            'NAME': 'app_data',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te'
        },
        'users': {
            'NAME': 'user_data_site2',
            'ENGINE': 'django.db.backends.mysql',
            'USER': 'mysql_user',
            'PASSWORD': 'priv4te'
        }
    }