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
---
* 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
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
---
* 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
Release history Release notifications | RSS feed
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.zip
(16.6 kB
view details)
django-domains-0.5.tar.gz
(9.0 kB
view details)
django-domains-0.5.tar.bz2
(7.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django-domains-0.5.zip.
File metadata
- Download URL: django-domains-0.5.zip
- Upload date:
- Size: 16.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ed09f2cd363db8aafe842cd31f734dc851ca82e39bdbd84890f334520014cca
|
|
| MD5 |
d4e13e639523379e1559cb8cc7225f36
|
|
| BLAKE2b-256 |
5a8c323dae642714952d377c5cea14d7401f1321b8de8f5e6cd1c26216bf9534
|
File details
Details for the file django-domains-0.5.tar.gz.
File metadata
- Download URL: django-domains-0.5.tar.gz
- Upload date:
- Size: 9.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37d92fac8a8602c16bc85ea0b7e68cc187db820ede43ff2aefcd6fcb45066ee4
|
|
| MD5 |
07034c03f61d0909b7a39dba78f45eec
|
|
| BLAKE2b-256 |
2c9d594091441a7d53bc0bc6800e17699abeee80ec2cd0fdbae9e3643d14af68
|
File details
Details for the file django-domains-0.5.tar.bz2.
File metadata
- Download URL: django-domains-0.5.tar.bz2
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68761e4057b95a495929b6f088c1e79cacb8c03e4c5fe9e21f13c9d7e3c5965a
|
|
| MD5 |
2a896afc5c69e918a3dc1cc6874b304d
|
|
| BLAKE2b-256 |
4479d326681d41e41ec8ce8f84bf8a02e6276100717186f24d17f59a68f47ccd
|
File details
Details for the file django_domains-0.5-py2.py3-none-any.whl.
File metadata
- Download URL: django_domains-0.5-py2.py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0abe67b8d587540233d7f27b61c2975b7a315301638ea6516c0e33c46f78b92c
|
|
| MD5 |
94fed8b3e0378b845118a61102c2b3ad
|
|
| BLAKE2b-256 |
0e7f3c4f05cdc29b69b0fafed6cfa9994292a947dcd65871571f2c572676e755
|