Single installation, multiple domains and apps?
I am planning to use Django for a multi-site project, where each site is mostly independent, but would share a few models across all the sites.
I am wondering if there is a way to make each Django 'app' it's own site, complete with unique domain name, and still allow each site to access a开发者_C百科 common app that contains some models for user accounts, profiles, etc.
The plan is to allow single sign on to each site, sharing the account information via the common app, and creating cookies for each site once the user logs in.
I know Django has a 'sites' feature, but i'm not sure if this is robust enough for my needs.
Can anyone recommend a way to do this or point me towards any articles that might help?
UPDATE
Just wondering, would it be possible via apache, and possibly some modification to the urls.py to be able to point a certain domain to a url structure?
for example, lets say the main site is mainsite.com, and i want one of the other domains to point to mainsite.com/secondarysite where secondarysite is a django app within the same instance, and have apache mask the fact that the secondarysite.com domain is actually pointing to a different location?
Re. your update: You don't need to fake the URL structure like that, unless you also want URLs like mainsite.com/secondarysite to be directly available to the user.
I'll assume you're using name-based virtual hosting. One simple but very flexible approach would be to have each <VirtualHost> directive invoke a different wsgi script via the usual mod_wsgi configuration directives, and then each wsgi script can set os.environ['DJANGO_SETTINGS_MODULE']
pointing to a different settings file.
Each of those settings files can have a different ROOT_URLCONF, so you can configure views at different paths if you need to. Leverage the include
mechanism.
If you want both domains to use the same database for everything, just have both settings files load the database config from a third file, eg. settings_shared.py. Or if you want to route some models to a shared database, and others not, that's possible too. It's easy to imagine how that could be configured for each domain:
from settings_shared import DATABASES_SHARED
DATABASES = DATABASES_SHARED.copy()
DATABASES.update({ ... })
This approach takes care of configuring URLs and databases for each domain. But it doesn't take care of single sign-on.
For the SSO portion, it really depends what sort of user experience you want and how much time you have ;)
Try searching for "django sso". There are a lot of relevant questions here, eg: Implementing Single Sign On (SSO) using Django, How to build a secure Django single signon between different sites?, Django + Google SSO openid, Integrating Django and .Net applications using Single Sign On (SSO), (Django) Sharing authentication across two sites that are on different domains
You might consider OpenID.
精彩评论