Skip to main content
==============
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.6.0
-----

* Drop support of older python versions (2.6, 3.2, 3.3)
* Drop support of older Django versions (1.6 and older)
* Add support for Python 3.5
* Add support for Django 1.9 (thanks to `Jordan Reiter <mailto:jordanreiter@gmail.com>`_
* Migrate to Django Applications API (thanks to `Jordan Reiter <mailto:jordanreiter@gmail.com>`_
* Improve PEP-0008 support and some minor code refactoring

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

Metadata

Release files for django-domains 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for django-domains 0.6
File Size Uploaded
django-domains-0.6.zip 18.1 kB Details
django-domains-0.6.tar.gz 9.8 kB Details
django-domains-0.6.tar.bz2 8.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-domains 0.6
File Interpreter ABI Platform
django_domains-0.6-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 50.9 kB

Release files / django-domains-0.6.zip

Download URL django-domains-0.6.zip
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
e6733761f7bbb8ef95419104d54ded74aae182c151c783171413e193e52b0853
BLAKE2b-256 checksum
How to use checksums
be55c9fafb6bd5be6da97a9cffe846141506982436b11559b6cdaef86d0d2012
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-domains-0.6.tar.gz

Download URL django-domains-0.6.tar.gz
Size 9.8 kB
Tags Source
SHA-256 checksum
How to use checksums
355abb03ed4bf03f9628a5f8b4cb2359fbe5537f14268453d9ddf09c68eb597d
BLAKE2b-256 checksum
How to use checksums
f4f6716ee90fd242ae349effa7c4969c2fd2c1762d7d3262331fd7bc3a78db51
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django-domains-0.6.tar.bz2

Download URL django-domains-0.6.tar.bz2
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5bf8c9b3bbe354febb48f9317594b398abd6b85066e5030d594c2befcd278e98
BLAKE2b-256 checksum
How to use checksums
f0caf83185e52e2d3aafc89016fa99f5cd37d24d1d8eed000f9f9b3bd2c8793a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_domains-0.6-py2.py3-none-any.whl

Download URL django_domains-0.6-py2.py3-none-any.whl
Size 14.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
0f9d225225a270a0d8f0768b359ffe8dc959844e49de1b383c3b182b861c473a
BLAKE2b-256 checksum
How to use checksums
61ed4db228f37d7b12300fe0f0dea947ade5348dfa995fa261fc5a2f99e54870
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.6 This release

4 release files

0.5.2

4 release files

0.5.1

4 release files

0.5

4 release files

0.4.1

4 release files

0.2

3 release files

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page