README
Install with pip:
pip install django-multisite
Or get the code via git:
git clone git://github.com/ecometrica/django-multisite.git django-multisite
Then run:
python setup.py install
Or add the django-multisite/multisite folder to your PYTHONPATH.
If you wish to contribute, instead run:
python setup.py develop
Quickstart
Replace your SITE_ID in settings.py to:
from multisite import SiteID SITE_ID = SiteID(default=1)
Add these to your INSTALLED_APPS:
INSTALLED_APPS = [
...
'django.contrib.sites',
'multisite',
...
]
Add to your settings.py TEMPLATES loaders in the OPTIONS section:
TEMPLATES = [
...
{
...
'DIRS': {...}
'OPTIONS': {
'loaders': (
'multisite.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
}
...
}
...
]
Edit settings.py MIDDLEWARE (MIDDLEWARE_CLASSES for Django < 1.10):
MIDDLEWARE = (
...
'multisite.middleware.DynamicSiteMiddleware',
...
)
Append to settings.py, in order to use a custom cache that can be safely cleared:
# The cache connection to use for django-multisite. # Default: 'default' CACHE_MULTISITE_ALIAS = 'multisite' # The cache key prefix that django-multisite should use. # If not set, defaults to the KEY_PREFIX used in the defined # CACHE_MULTISITE_ALIAS or the default cache (empty string if not set) CACHE_MULTISITE_KEY_PREFIX = ''
If you have set CACHE_MULTISITE_ALIAS to a custom value, e.g. 'multisite', add a separate backend to settings.py CACHES:
CACHES = {
'default': {
...
},
'multisite': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'TIMEOUT': 60 * 60 * 24, # 24 hours
...
},
}
Multisite determines the ALLOWED_HOSTS by checking all Alias domains. You can also set the MULTISITE_EXTRA_HOSTS to include additional hosts. This can include wildcards.:
MULTISITE_EXTRA_HOSTS = ['example.com'] # will match the single additional host MULTISITE_EXTRA_HOSTS = ['.example.com'] # will match any host ending '.example.com'
Development Environments
Multisite returns a valid Alias when in “development mode” (defaulting to the alias associated with the default SiteID.
- Development mode is either:
Running tests, i.e. manage.py test
Running locally in settings.DEBUG = True, where the hostname is a top-level name, i.e. localhost
In order to have multisite use aliases in local environments, add entries to your local etc/hosts file to match aliases in your applications. E.g.
127.0.0.1 example.com 127.0.0.1 examplealias.com
And access your application at example.com:8000 or examplealias.com:8000 instead of the usual localhost:8000.
Domain fallbacks
By default, if the domain name is unknown, multisite will respond with an HTTP 404 Not Found error. To change this behaviour, add to settings.py:
# The view function or class-based view that django-multisite will
# use when it cannot match the hostname with a Site. This can be
# the name of the function or the function itself.
# Default: None
MULTISITE_FALLBACK = 'django.views.generic.base.RedirectView
# Keyword arguments for the MULTISITE_FALLBACK view.
# Default: {}
MULTISITE_FALLBACK_KWARGS = {'url': 'http://example.com/',
'permanent': False}
Templates
If required, create template subdirectories for domain level templates (in a location specified in settings.TEMPLATES[‘DIRS’].
Multisite’s template loader will look for templates in folders with the names of domains, such as:
templates/example.com
The template loader will also look for templates in a folder specified by the optional MULTISITE_DEFAULT_TEMPLATE_DIR setting, e.g.:
templates/multisite_templates
Tests
To run the tests:
python setup.py test
Or:
pytest
Before deploying a change, to verify it has not broken anything by running:
tox
This runs the tests under every supported combination of Django and Python.
Metadata
Release files for django-multisite 1.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-multisite-1.9.0.tar.gz | 25.4 kB | Without provenance | Details for django-multisite-1.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_multisite-1.9.0-py3-none-any.whl | Python 3 | none | any | Details for django_multisite-1.9.0-py3-none-any.whl |
Total release size: 56.4 kB
Release files / django-multisite-1.9.0.tar.gz
| Download URL | django-multisite-1.9.0.tar.gz |
|---|---|
| Size | 25.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5254dc2df69a6315f5ac05cbbfbb045b361044e739c8849d66151847816d8299
|
|
BLAKE2b-256 checksum How to use checksums |
db90ea21931bc1fa5ad4bd23e957d979967a8b0c287a242058060aeda58a6882
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12
|
Release files / django_multisite-1.9.0-py3-none-any.whl
| Download URL | django_multisite-1.9.0-py3-none-any.whl |
|---|---|
| Size | 31.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
266216fb39a6c61a058a5fe0eef3988c26e5bb4f3af6d3f35b41a3a779279336
|
|
BLAKE2b-256 checksum How to use checksums |
c8bf0472ef58086eb967d6c18803c5ce1479400ea37f9693152ad70355e84994
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.6.12
|
Security for django-multisite 1.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.