Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

This branch is 13 commits ahead, 2 commits behind develop

Fetching latest commit…

Cannot retrieve the latest commit at this time

..
Failed to load latest commit information.
test_app
README.creole
__init__.py
admin.py
middleware.py
models.py
test_settings.py
tests.py

README.creole

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 
Something went wrong with that request. Please try again.