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 bac开发者_JAVA百科kend?
How can I accomplish this?
Thanks.
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).
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.
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/
精彩评论