Domanda

I want to implement the concepts of Multiple sites to my project, for that I have studied the official "site framework " tutorial of django and other tutorials also.

But I am little bit confuse from where I should start, because as given in doc there are multiple site id's are used.But I have one as usual. And in some docs there are some editing is done in HTTPD.conf file

So I didn't understand from docs, from where I should start ?

So please can any body tell me the steps of implementing multi site.

È stato utile?

Soluzione

This is very simple principle. You have the Site model where you define your sites and then you refer to this model in your models. Say we create a blog application and you will have:

Site model:

ID | domain             | name
1  | site-a.example.com | John's blog
2  | site-b.example.com | David's blog

BlogArticle:

ID | site_id | title                         | ...
1  | 1       | Some title for John's article | ...
2  | 1       | Another post by John          | ...
3  | 2       | David's blog post             | ...

How will be this deployed on the web server? Your blog app code is the same for every blog so you place it somewhere in the Python path where site-a and site-b installations can import it (commonly you create a virtualenv and install your blog app there). Now you create two virtual webs for both domains - site-a.example.com and site-b.example.com and for each site you create a separate django project (this is more like a site profile than a regular project). Now, how do you know which project is for which blog? You define the SITE_ID constant in every project settings pointing to the Site id for such blog and to list all articles for given blog you add the your current site to the filter condition.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top