Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

74 lines (52 sloc) 1.921 kB

Dynamic SITE ID

Set the SITE_ID dynamic by the current Domain Name. You can also specify domain name alias as a simple string or as a regular expression.

some Sourcecode parts are borrowed from:

See also:

usage

Add DynamicSiteMiddleware as the first middleware to settings, e.g:

MIDDLEWARE_CLASSES = (
    'django_tools.dynamic_site.middleware.DynamicSiteMiddleware',
    ...
)
INSTALLED_APPS = (
    'django_tools.dynamic_site',
    ...
)
    
# activate django-tools DynamicSiteMiddleware:
USE_DYNAMIC_SITE_MIDDLEWARE = True

logging

For logging into a file, add this to you settings, e.g.:

import logging
logger = logging.getLogger("django_tools.DynamicSite")
logger.setLevel(logging.DEBUG)
logger.handlers = [logging.FileHandler('DynamicSite.log')] # setting would be import more than one time

For developing e.g:

if "runserver" in sys.argv or "tests" in sys.argv:
    logger.setLevel(logging.DEBUG)
    logger.addHandler(logging.StreamHandler())

limitations

defaults

You can't set the default ID in model fields with default=settings.SITE_ID becuase this will be evalutated at startup. So it won't change dynamically. Work-a-round: Set it in __init__()

unittests

Note: Dynamic SITE ID is problematic in unittests. To avoid this, add theses lines in you test runner file:

from django.conf import settings

# Disable dynamic site, if used:
if getattr(settings, "USE_DYNAMIC_SITE_MIDDLEWARE", False):
    settings.USE_DYNAMIC_SITE_MIDDLEWARE = False
    settings.SITE_ID = 1 
Jump to Line
Something went wrong with that request. Please try again.