django-hosts
============
.. image:: https://img.shields.io/pypi/v/django-hosts.svg
:target: https://pypi.python.org/pypi/django-hosts
.. image:: https://img.shields.io/pypi/pyversions/django-hosts.svg
:target: https://pypi.org/project/django-hosts/
.. image:: https://img.shields.io/pypi/djversions/django-hosts.svg
:target: https://pypi.org/project/django-hosts/
.. image:: https://github.com/jazzband/django-hosts/workflows/Test/badge.svg
:target: https://github.com/jazzband/django-hosts/actions
.. image:: https://codecov.io/gh/jazzband/django-hosts/branch/master/graph/badge.svg
:target: https://codecov.io/gh/jazzband/django-hosts
.. image:: https://readthedocs.org/projects/django-hosts/badge/?version=latest&style=flat
:target: https://django-hosts.readthedocs.io/en/latest/
.. image:: https://jazzband.co/static/img/badge.svg
:target: https://jazzband.co/
This Django app routes requests for specific hosts to different URL schemes
defined in modules called "hostconfs".
For example, if you own ``example.com`` but want to serve specific content
at ``api.example.com`` and ``beta.example.com``, add the following to a
``hosts.py`` file:
.. code-block:: python
from django_hosts import patterns, host
host_patterns = patterns('path.to',
host(r'api', 'api.urls', name='api'),
host(r'beta', 'beta.urls', name='beta'),
)
This causes requests to ``{api,beta}.example.com`` to be routed to their
corresponding URLconf. You can use your ``urls.py`` as a template for these
hostconfs.
Patterns are evaluated in order. If no pattern matches, the request is
processed in the usual way, ie. using the standard ``ROOT_URLCONF``.
The patterns on the left-hand side are regular expressions. For example,
the following ``ROOT_HOSTCONF`` setting will route ``foo.example.com``
and ``bar.example.com`` to the same URLconf.
.. code-block:: python
from django_hosts import patterns, host
host_patterns = patterns('',
host(r'(foo|bar)', 'path.to.urls', name='foo-or-bar'),
)
.. note:
Remember:
* Patterns are matched against the extreme left of the requested host
* It is implied that all patterns end either with a literal full stop
(ie. ".") or an end of line metacharacter.
* As with all regular expressions, various metacharacters need quoting.
Installation
------------
First, install the app with your favorite package manager, e.g.:
.. code-block:: shell
pip install django-hosts
Alternatively, use the `repository on Github`_.
You can find the full docs here: `django-hosts.rtfd.org`_
Then configure your Django site to use the app:
#. Add ``'django_hosts'`` to your ``INSTALLED_APPS`` setting.
#. Add ``'django_hosts.middleware.HostsRequestMiddleware'`` to the
**beginning** of your ``MIDDLEWARE`` setting.
#. Add ``'django_hosts.middleware.HostsResponseMiddleware'`` to the **end** of
your ``MIDDLEWARE`` setting.
#. Create a new module containing your default host patterns,
e.g. in the ``hosts.py`` file next to your ``urls.py``.
#. Set the ``ROOT_HOSTCONF`` setting to the dotted Python
import path of the module containing your host patterns, e.g.:
.. code-block:: python
ROOT_HOSTCONF = 'mysite.hosts'
#. Set the ``DEFAULT_HOST`` setting to the **name** of the host pattern you
want to refer to as the default pattern. It'll be used if no other
pattern matches or you don't give a name to the ``host_url`` template
tag.
.. _`repository on Github`: https://github.com/jazzband/django-hosts
.. _`django-hosts.rtfd.org`: https://django-hosts.readthedocs.io/
Raw data
{
"_id": null,
"home_page": "https://django-hosts.readthedocs.io/",
"name": "django-hosts",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Jannis Leidel",
"author_email": "jannis@leidel.info",
"download_url": "https://files.pythonhosted.org/packages/b0/05/217d45b4e5f0003d19322badae2ba96f242f42e51626402437b0839f2fb8/django-hosts-6.0.tar.gz",
"platform": null,
"description": "django-hosts\n============\n\n.. image:: https://img.shields.io/pypi/v/django-hosts.svg\n :target: https://pypi.python.org/pypi/django-hosts\n\n.. image:: https://img.shields.io/pypi/pyversions/django-hosts.svg\n :target: https://pypi.org/project/django-hosts/\n\n.. image:: https://img.shields.io/pypi/djversions/django-hosts.svg\n :target: https://pypi.org/project/django-hosts/\n\n.. image:: https://github.com/jazzband/django-hosts/workflows/Test/badge.svg\n :target: https://github.com/jazzband/django-hosts/actions\n\n.. image:: https://codecov.io/gh/jazzband/django-hosts/branch/master/graph/badge.svg\n :target: https://codecov.io/gh/jazzband/django-hosts\n\n.. image:: https://readthedocs.org/projects/django-hosts/badge/?version=latest&style=flat\n :target: https://django-hosts.readthedocs.io/en/latest/\n\n.. image:: https://jazzband.co/static/img/badge.svg\n :target: https://jazzband.co/\n\nThis Django app routes requests for specific hosts to different URL schemes\ndefined in modules called \"hostconfs\".\n\nFor example, if you own ``example.com`` but want to serve specific content\nat ``api.example.com`` and ``beta.example.com``, add the following to a\n``hosts.py`` file:\n\n.. code-block:: python\n\n from django_hosts import patterns, host\n\n host_patterns = patterns('path.to',\n host(r'api', 'api.urls', name='api'),\n host(r'beta', 'beta.urls', name='beta'),\n )\n\nThis causes requests to ``{api,beta}.example.com`` to be routed to their\ncorresponding URLconf. You can use your ``urls.py`` as a template for these\nhostconfs.\n\nPatterns are evaluated in order. If no pattern matches, the request is\nprocessed in the usual way, ie. using the standard ``ROOT_URLCONF``.\n\nThe patterns on the left-hand side are regular expressions. For example,\nthe following ``ROOT_HOSTCONF`` setting will route ``foo.example.com``\nand ``bar.example.com`` to the same URLconf.\n\n.. code-block:: python\n\n from django_hosts import patterns, host\n\n host_patterns = patterns('',\n host(r'(foo|bar)', 'path.to.urls', name='foo-or-bar'),\n )\n\n.. note:\n\n Remember:\n\n * Patterns are matched against the extreme left of the requested host\n\n * It is implied that all patterns end either with a literal full stop\n (ie. \".\") or an end of line metacharacter.\n\n * As with all regular expressions, various metacharacters need quoting.\n\nInstallation\n------------\n\nFirst, install the app with your favorite package manager, e.g.:\n\n.. code-block:: shell\n\n pip install django-hosts\n\nAlternatively, use the `repository on Github`_.\n\nYou can find the full docs here: `django-hosts.rtfd.org`_\n\nThen configure your Django site to use the app:\n\n#. Add ``'django_hosts'`` to your ``INSTALLED_APPS`` setting.\n\n#. Add ``'django_hosts.middleware.HostsRequestMiddleware'`` to the\n **beginning** of your ``MIDDLEWARE`` setting.\n\n#. Add ``'django_hosts.middleware.HostsResponseMiddleware'`` to the **end** of\n your ``MIDDLEWARE`` setting.\n\n#. Create a new module containing your default host patterns,\n e.g. in the ``hosts.py`` file next to your ``urls.py``.\n\n#. Set the ``ROOT_HOSTCONF`` setting to the dotted Python\n import path of the module containing your host patterns, e.g.:\n\n .. code-block:: python\n\n ROOT_HOSTCONF = 'mysite.hosts'\n\n#. Set the ``DEFAULT_HOST`` setting to the **name** of the host pattern you\n want to refer to as the default pattern. It'll be used if no other\n pattern matches or you don't give a name to the ``host_url`` template\n tag.\n\n.. _`repository on Github`: https://github.com/jazzband/django-hosts\n.. _`django-hosts.rtfd.org`: https://django-hosts.readthedocs.io/\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Dynamic and static host resolving for Django. Maps hostnames to URLconfs.",
"version": "6.0",
"project_urls": {
"Homepage": "https://django-hosts.readthedocs.io/",
"Source": "https://github.com/jazzband/django-hosts"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d5abad0298e961e709108b34e64ce490064723063296efdd48dc29f38d2864dd",
"md5": "3f87d2ba5e9f10d833ffa08bcbf6e933",
"sha256": "34a97a183b3fb8a00de3e0a8af5355a25ff5203019d2e213edd8f12c330cc303"
},
"downloads": -1,
"filename": "django_hosts-6.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3f87d2ba5e9f10d833ffa08bcbf6e933",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 27799,
"upload_time": "2023-10-27T13:54:17",
"upload_time_iso_8601": "2023-10-27T13:54:17.987258Z",
"url": "https://files.pythonhosted.org/packages/d5/ab/ad0298e961e709108b34e64ce490064723063296efdd48dc29f38d2864dd/django_hosts-6.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b005217d45b4e5f0003d19322badae2ba96f242f42e51626402437b0839f2fb8",
"md5": "d52b433dd7ff97b971ad48e60dd5b8cb",
"sha256": "e7aec357504d36f384c65fba67deabc4552f36f347b96bb7a3d131a1250d7299"
},
"downloads": -1,
"filename": "django-hosts-6.0.tar.gz",
"has_sig": false,
"md5_digest": "d52b433dd7ff97b971ad48e60dd5b8cb",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 36429,
"upload_time": "2023-10-27T13:54:12",
"upload_time_iso_8601": "2023-10-27T13:54:12.244568Z",
"url": "https://files.pythonhosted.org/packages/b0/05/217d45b4e5f0003d19322badae2ba96f242f42e51626402437b0839f2fb8/django-hosts-6.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-27 13:54:12",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jazzband",
"github_project": "django-hosts",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "django-hosts"
}