Separate Django sites with a common authetication/registration backend
Asked Answered
I

3

6

I need split my current Django application into two sites.

Site A will contain the public facing site which would contain all the static pages and the registration system.

The other site — Site B — is the site for registered users. They can also log-in to application site through Site B.

If I'm not mistaken, I can use django.contrib.sites framework to accomplish the task of having multiple sites but can have a common authetication/registration backend?

How can I accomplish this?

Thanks.

Inez answered 7/9, 2011 at 13:16 Comment(1)
+1 : never had that situation, but always was thing how to use multiple sites in my django app!Libertine
A
2

Django's django.contrib.sites framework is nice if both sites are running under the same server and access the same database. If you have a distributed application (different sites on different hosts or different sites on different databases), you can resort to single sign-on solutions.

I use OpenID with a custom provider to centralize logins between apps running on different databases. Other solutions include CAS (provider and consumer).

Agateware answered 7/9, 2011 at 16:6 Comment(0)
F
2

For this case, you would have 2 settings.py files called settings_A.py and settings_B.py which specify from settings import *

A would have SITE=1 and B would have SITE=B. you can then set these files in your apache configs by setting the environment variable for each virtual host DJANGO_SETTINGS_MODULE=settings_A and DJANGO_SETTINGS_MODULE=settings_B

Then you set up the contrib.sites app with your 2 domain names bound to the appropriate site ID, and your flatpages will be able to be bound to either or both sites.

Lastly, in settings_A.py settings_B.py you either specify seperate root urlconfs or you use the use settings.SITE in your urlconfs to enable and disable groups of urls for each site.

Hope this helps

EDIT: To clarify: as long as you use the same database and SECRET_KEY between both sites, you can use the same user accounts between them too. If the sites are of the form example.com and private.example.com then setting SESSION_COOKIE_DOMAIN to .example.com will allow the session to carry over between both sites.

Foxy answered 7/9, 2011 at 14:12 Comment(2)
Hi Thomas. This sound about reasonable. Does this mean, that a person who logs in to site A will be able to log in to Site B? A good exmaple is Google, if you login on their homepage, you can access your Gmail, Docs, etc. I need to implement something similar — cross-domain authenticaton. Thanks.Inez
you can only do cross-domain automatic login by default if both domains share a root domain, e.g. domain.com, sitea.domain.com and siteb.domain.com. (this is why all google sites use google.com as their base domain). You can however have one User object that can be used for logging into both sites. For persistent logins between totally diferent domains, try this: #263510Foxy
A
2

Django's django.contrib.sites framework is nice if both sites are running under the same server and access the same database. If you have a distributed application (different sites on different hosts or different sites on different databases), you can resort to single sign-on solutions.

I use OpenID with a custom provider to centralize logins between apps running on different databases. Other solutions include CAS (provider and consumer).

Agateware answered 7/9, 2011 at 16:6 Comment(0)
B
0

You could use (external) LDAP authentication for both sites. You would need a LDAP server somewhere reachable for both sites. I never used this and I don't know how well it integrates with Django auth though. See http://packages.python.org/django-auth-ldap/

Burlie answered 7/9, 2011 at 14:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.