Django-CMS: Multiple domains on same project

django, django-cms, python, python-2.7

Solution

Why are you setting the `SITE_ID` statically? You should probably create two settings files and use some form of inheritance depending on project differentiation, e.g.:

local_settings.py (not under version control holds sensitive data like database passwords and the secret key)

SECRET_KEY = 'as!sfhagfsA@$1AJFS78787124!897zR81'

settings.py (holds settings that are equal for both sites)

# preferably at the bottom
try:
    from local_settings import *
except ImportError:
    pass

settings_foo.py (holds settings specific to site 1)

from settings import *

SITE_ID = 1

settings_bar.py (holds settings specific to site 2)

from settings import *

SITE_ID = 2

settings_deployment_foo.py (overwrites variables for production)

from settings_foo import *

DEBUG = False

settings_deployment_bar.py (overwrites variables for production)

from settings_bar import *

DEBUG = False

Then just create two sites within `admin/sites` or use a fixture (assuming you are sharing a database cross these projects you'll only have to do this once).

Problem

i'm trying to run django-cms on two different domains. For that i created two domains (django.contrib.sites) and added to them django-cms pages. Now i created a SiteDetectionMiddleware: ``` class SiteDetectionMiddleware: def process_request(self, request): settings.SITE_ID = 1 host = request.META.get('HTTP_HOST') if host: try: site = Site.objects.get(domain=host) settings.SITE_ID = site.id except Site.DoesNotExist: pass ``` It seems to work correctly, when i call the website in browser for the first time after restarting apache. Then i changed to the other site and got a NoReverseMatch Error. Does anyone have an idea what could be wrong? I thought this should work out of the box in django-cms? regards Colin

Original source