Skip to main content

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

Project description

==============
django-domains
==============


.. image:: https://badge.fury.io/py/django-domains.png
:target: http://badge.fury.io/py/django-domains

.. image:: https://travis-ci.org/marazmiki/django-domains.png?branch=master
:target: https://travis-ci.org/marazmiki/django-domains

.. image:: https://coveralls.io/repos/marazmiki/django-domains/badge.png?branch=master
:target: https://coveralls.io/r/marazmiki/django-domains?branch=master

.. image:: https://pypip.in/d/django-domains/badge.png
:target: https://pypi.python.org/pypi/django-domains


Installation
------------

1. Install the package

.. code:: bash

pip install django-domains

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

.. code:: python

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:

.. code:: python

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

3. Run tests:

.. code:: bash

./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` :)

.. code:: python

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:

.. code:: python

DOMAINS_TEMPLATE_NAME_FUNCTION = 'my.project.utils.my_custom_template_name'



0.5.2
-----

* Update head django versions


0.5.1
-----

* Update head django versions

0.5
---
* Added support Django 1.8
* New hook machinery

0.2
---

* Improves pep8;
+ Support for Django 1.4, Django 1.5, Django 1.6, Django1.7
+ Added Travis CI integration

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

django-domains-0.5.2.zip (16.8 kB view details)

Uploaded Source

django-domains-0.5.2.tar.gz (9.1 kB view details)

Uploaded Source

django-domains-0.5.2.tar.bz2 (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_domains-0.5.2-py2.py3-none-any.whl (13.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-domains-0.5.2.zip.

File metadata

  • Download URL: django-domains-0.5.2.zip
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-domains-0.5.2.zip
Algorithm Hash digest
SHA256 1229c310eef0009b6475fa8b90e4c6c073cd2eb67221894732a18f6d7cbc5b0c
MD5 76c92a9f7b11b936d66733a9dc80b60d
BLAKE2b-256 f123a8ce12216ccf84470dfbc8364043087c7b73d96e1bd99d874f4f81330067

See more details on using hashes here.

File details

Details for the file django-domains-0.5.2.tar.gz.

File metadata

File hashes

Hashes for django-domains-0.5.2.tar.gz
Algorithm Hash digest
SHA256 24b5c741137005b8bfdf9b9f8f2d9f662e5a2099389b5a5ca4851b65b9c2960d
MD5 369e9853033b766d2c4f79488ece5d88
BLAKE2b-256 8d24babc3f63a7af49e851275f715ef7fadbdfae4ec13b8723a756b1b0b2f1e4

See more details on using hashes here.

File details

Details for the file django-domains-0.5.2.tar.bz2.

File metadata

File hashes

Hashes for django-domains-0.5.2.tar.bz2
Algorithm Hash digest
SHA256 1a3cb5c19df78b870d5a82c548b7a07133d8063467620b486f5f0acab9b500bd
MD5 4a1e5c478b19c4be40c5d8cd11eecf3b
BLAKE2b-256 4c0bb2374a437bdd89e3fbf09632c2f2a1f3bac5a0b73a6ac32dbad71e20cd98

See more details on using hashes here.

File details

Details for the file django_domains-0.5.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_domains-0.5.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c8b5ccb75418e04bdabe1335bb6601722a5215587e1ce166633ac2b8583afa26
MD5 6348cfe564ca799cec68dcf4c9f22899
BLAKE2b-256 a1b7d0b96e645c8865a20ffde4c8f10ce06baf8a0266ec98785365d71f41f110

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page