12

How to setup a django-cms project to support multiple websites?

There's no reference to this in the official documentation and only limited information in the mailing list, but it's in the headline "A Django application for managing hierarchical pages of content, possibly in multiple languages and/or on multiple sites." and through the Django Sites Framework there's already built in support, and in the admin pages can be associated to different sites.

Related:

Django-CMS: Multiple domains on same project

Community
  • 1
  • 1
Stefano
  • 18,083
  • 13
  • 64
  • 79
  • 1
    This is a recurrent question on the mailing list so I thought I'd add my answer where it can be easily found... – Stefano Sep 24 '13 at 08:54

1 Answers1

10

there are a few different options to manage different websites (and, thus, templates and page contents) in Django-cms.

The basic approach

My favorite is probably the simplest:

In my virtualenv I have a single django-cms installation AND a single "project" that contains ALL the templates I use.

I have a global settings file plus one for each website that does only import all global settings and set "SITE_ID".

from base import *
SITE_ID = XXX

For structure i usually have a settings folder, an empty __init__.py inside, a base.py with all the common settings - including django-cms settings, and then the different websites eg. site1.py site2.py etc. (sometimes my structure is even slightly more complex to also account for dev/production, different machines, etc. but that's not relevant here).

I launch each website as a different instance - I use gunicorn so that's extremely easy too, each one of a different port.

I have an nginx fronted with a separate server configuration for each of my websites, and each of these points to a different gunicorn.

server {
    listen      80;
    server_name example1.com www.example1.com;
    ...
    location / {
        proxy_pass  http://localhost:PORT;
    }

}

Any of the gunicorn instances can access the admin, and all the data is shared in a single database, but for simplicity

That's all!

Of course it can be done similarly with Apache, mod_wsgi and different virtualhosts.

Advanced

Themes

I actually structured my folders to have an apps folder called themes. Each theme is actually an APP, though mostly contains only the templates and static folders, and it's added to the INSTALLED_APPS. This allows for cute things such as inheritance and/or overriding between different themes.

Dynamic SITE_ID

It's also possible to use a middleware that will dynamically extract and set the SITE_ID from the URL. This allows to have one single instance... but I don't see any real advantage in this solution and rather find it a potential source of risks.

Stefano
  • 18,083
  • 13
  • 64
  • 79
  • Any idea how to have a page such across all the sites? Such as an 'about' page. There is an unanswered question on the mailing list about it. – straykiwi Nov 24 '14 at 21:42
  • Sorry @straykiwi - not sure how I would do it. I would like to expand on this answer since I made some further improvements (eg. set up rights so that only a super admin can see all the different sites, and then have a group for users only able to access individual sites) - but I don't have an easy access to a django-cms system anymore, as I moved to a different company since. – Stefano Dec 01 '14 at 13:35
  • Is this still the way you'd do it today? Do the different sites use different templates? – ratatoskr Jan 05 '17 at 15:42
  • sorry @ratatoskr but my previous comment still holds: i'm not currently working with django-cms... – Stefano Jan 19 '17 at 16:11