Best practice - Django multisite
I''m currently looking for a 'best practice' way to create a specific structure for my Django installation with multiple sites & subdomains.
I was thinking开发者_开发技巧 about the following:
/static
/global
- global js
- global css,
- etc..
/specific
- specific js
- etc..
/django
- contains all specific django files
/apps
- contains all the apps
/site1
- .py files
- specific apps (link to /django/apps/app)
- other site specific files
/site2
- .py files
- specific apps (link to /django/apps/app)
- other site specific files
/subdomain.site2
- .py files
- specific apps (link to /django/apps/app)
- other site specific files
I think the above is quite reasonable, to keep all site, and in a less way also the subdomains seperate from each other. I know this is a 'best practice' but some (critical) advisement would be appreciated ;)
I think this depends on how you are going to build and deploy your multidomain "site". Django has the sites framework: http://docs.djangoproject.com/en/dev/ref/contrib/sites/ which can allow you to implement the "news article sharing" you mentioned.
But deploying a multidomain django isn't trivial if you want all of them to use a single process (with mod_wsgi you have for example a virtualhost item for each one), and that might become an issue if you have many domains/subdomains.
For the standard way of deploying django, every django project (1 per domain) will have its own virtualenv (or share one if they use the same libraries), and all library apps will reside in the python path of the virtualenv.
Every project should be self contained, so you would then have, for example:
project1
--coreapps/projectspecificapps...
--templates/
--media/
--settings.py
--urls.py
--manage.py
project2
--coreapps/projectspecificapps..
--templates/
--media/
--settings.py
--urls.py
--manage.py
Anything that is shared between projects should be separated from a project and should be an APP of it's own, anywhere on the python path (inside the virtualenv for example).
For many domains/subdomains... its a whole different story. You can have django handle the domain part with a django middleware (or maybe a wsgi middleware? - there might be an interesting solution out there using wsgi), and you would have to make your apps, templates, etc... domain "aware" somehow, that somehow depending on your specific needs.
http://www.b-list.org/weblog/2006/sep/10/django-tips-laying-out-application/
Django and project/application organization
and look at popular apps to see how they are used: http://djangopackages.com/
精彩评论