django-domains 0.1

An application that allows you to run many different sites on one Django instance

  Add it to your Download Basket!

 Add it to your Watch List!

0/5

Rate it!
send us
an update
LICENSE TYPE:
Other/Proprietary License
USER RATING:
UNRATED
  0.0/5
DEVELOPED BY:
marazmiki
HOMEPAGE:
pypi.python.org
CATEGORY:
ROOT \ Internet \ HTTP (WWW)
django-domains is a Django app that allows you to run many different sites on one Django instance.

Installation

1. Install the package

pip install django-domains

2. Open settings.py and add middlewares into end of MIDDLEWARE_CLASSES tuple:

MIDDLEWARE_CLASSES += (
 'domains.middleware.RequestMiddleware',
 'domains.middleware.DynamicSiteMiddleware',
)


First middleware domains.middleware.RequestMiddleware is required, because it sets the request object into local thread.

Second middleware domains.middleware.DynamicSiteMiddleware is optional. You can use it for dynamical changing SITE_ID parameter corresponding site's PK with requested domains (see Django sites framework).

If you also want to use different templates for domains, add template loaders in begin of TEMPLATE_LOADERS tuple:

TEMPLATE_LOADERS = (
 'domains.loaders.filesystem.Loader',
 'domains.loaders.app_directories.Loader',
 # another loaders
)


 Run tests:

./manage.py test domains

Usage

If you want to use different template sets for each domains, just create directories with name domainname.tld (don't forget add TEMPLATE_LOADERS as figured in Installation) and put templates here.

Also you can use custom function that builds domain name. You must add DOMAINS_TEMPLATE_NAME_FUNCTION attribute into your settings.py and specify path to naming function.

Function must return tuple with path fragments. This fragments will be joined into full template path with django-domains.

Expect you call this function my_custom_template_name and placed it in my/project/utils.py:

Btw, you can access to request :)

def my_custom_template_name(template_dir, template_name):
 """
 This function generates template path in format:

 {template_dir}/custom/domains/{host}/{template_name}
 """
 from domains.utils import get_request

 request = get_request()

 return (template_dir, 'custom', 'domains', request.get_host,
 template_name)


Add into your settings.py this line:

DOMAINS_TEMPLATE_NAME_FUNCTION = 'my.project.utils.my_custom_template_name'

Last updated on November 24th, 2011

requirements

#Django instance #Django domains #Django #domains #instance #sites

Add your review!

SUBMIT