django-multisite support for DjangoCMS
Supported Django versions:
- Django 3.0
- Django 2.2
Supported django CMS versions:
- django CMS 3.7
- A virtualenv up and running
- DjangoCMS working
pip install djangocms-multisite
Open your
settings.pyfileWe need to add the configurations for django-multisite :
Replace SITE_ID value with the SiteID function:
from multisite import SiteID SITE_ID = SiteID(default=1)
Add
multisite,djangocms_multisitetoINSTALLED_APPS:INSTALLED_APPS=[ ... 'multisite', 'djangocms_multisite', ... ]Add those loders in the TEMPLATES setting:
TEMPLATES = [ ... { ... 'DIRS': {...} 'OPTIONS': { 'loaders': ( 'multisite.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', ) } ... } ... ]For other settings (cache, etc.) check the django-multisite page
Add
multisite.middleware.DynamicSiteMiddlewareanddjangocms_multisite.middleware.CMSMultiSiteMiddlewaretoMIDDLEWARE_CLASSES. The order is important:multisite.middleware.DynamicSiteMiddlewaremust be applied beforecms.middleware.utils.ApphookReloadMiddleware, whiledjangocms_multisite.middleware.CMSMultiSiteMiddlewaremust be right after:MIDDLEWARE_CLASSES = [ ... 'multisite.middleware.DynamicSiteMiddleware', 'cms.middleware.utils.ApphookReloadMiddleware', 'djangocms_multisite.middleware.CMSMultiSiteMiddleware', ... ]Configure the URL mapping as follows. The tests.test_utils.urls1 path can be the main urlconf file that you already have in your project. And it can be the same for all the domains if you need the same structure.:
MULTISITE_CMS_URLS={ 'www.example.com': 'tests.test_utils.urls1', 'www.example2.com': 'tests.test_utils.urls2', } MULTISITE_CMS_ALIASES={ 'www.example.com': ('alias1.example.com', 'alias2.example.com',), 'www.example2.com': ('alias1.example2.com', 'alias2.example2.com',), } MULTISITE_CMS_FALLBACK='www.example.com'Run
python manage.py makemigrationsRun
python manage.py migrateto apply the django-multisite migrations
Dictionary (or OrderedDict) containing the mapping between the domain (as configured in django
sites) and the corresponding urlconf.
The default domain to load if any of the above does not match.
Dictionary (or OrderedDict) containing the mapping between the domain (as configured in django
sites) and a list of aliases. This is optional if all the aliases are configured as
django-multisite aliases
- Domains in
MULTISITE_CMS_URLSmust be the same created in your database (via the interface inHome › Sites › Sites).