Domanda

How can I get a few sites similar in functionality, but different in appearance and content - all data will be different.

Change SITE_ID on the fly and write own template loader & staticfile finder (same URL /static/ for different sites indicates to different categories) and add ForeignKey to Site for all?

or are there other ways to?

Thanks!

È stato utile?

Soluzione

I did something similar to yourself.

I have a helper method in my views which gets the host.

def getHost(request): return request.META['SERVER_NAME']

Then depending on the host i have my static dir broken into the 2 sites static/host1/ static/host2/

and i do the same for templates i split it into 2 directories and call the appropriote one!

Altri suggerimenti

It is a delicate operation to split a Django site on the same instance. First, you have to have your models in mind. Like FlatPages do, your models may contain a ManyToManyField to the Sites table so you can filter content according to the current site if you want.

About templates and static data, I like Mark's answer but you can do it differently though. You could split your template and static folders into several folders with different themes and template configurations. For example, you could have only one set of templates, and two "themes" like this :

templates 
    / normal_set
static 
    / themes 
        / blue
        / red

You could create a table calles SiteConfiguration, with a OneToOneField to the Sites table. This configuration table would contain the name of the template folder and the name of the theme folder for the site so you can share properties between sites. Maybe you can cache this afterwards to avoid hitting the database too often. Mix this suggestion with Mark's one, maybe.

I assume your users remain the same through every site.

There are 2 packages designed for this exact use case:

for Django 1.8+, there is https://bitbucket.org/levit_scs/django-polla

If you are using an older version of Django, you can use https://bitbucket.org/uysrc/django-dynamicsites/overview

Even though this answer is quite late, I do hope it can help people stumbling on this question

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