django-hosts travis-ci python

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.

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/travis/jazzband/django-hosts.svg :target: https://travis-ci.org/jazzband/django-hosts

.. image:: https://img.shields.io/coveralls/jazzband/django-hosts.svg :target: https://coveralls.io/r/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::

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.

and bar.example.com to the same URLconf.
and bar.example.com to the same URLconf.
and bar.example.com to the same URLconf.
and bar.example.com to the same URLconf.
onf.

::

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.::

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 or MIDDLEWARE_CLASSES setting.

#. Add 'django_hosts.middleware.HostsResponseMiddleware' to the end of your MIDDLEWARE or MIDDLEWARE_CLASSES 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.::

   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/

Related Repositories

django-hosts

django-hosts

Dynamic and static host resolving for Django. Maps hostnames to URLconfs. ...

django-kitsune

django-kitsune

Host server monitoring app for Django Admin. Allows to schedule checks on hosts and notify results to administrators by mail. ...

django-sites-tools

django-sites-tools

DEPRECATED Use django-hosts instead! ...

django-hosts

django-hosts

Dynamic (and static) hosts support for Django ...

CFE-Django-Hosts

CFE-Django-Hosts

Learn how to implement Django Hosts (https://kirr.co/orhp9i) in your Django project. ...


Top Contributors

jezdez lamby timgraham bretth philipn mvantellingen bak1an adamchainz apollo13 jefftriplett justinvelluppillai MarkusH MikeVL charettes

Releases

-   2.0 zip tar
-   1.4 zip tar
-   1.3 zip tar
-   1.2 zip tar
-   1.1 zip tar
-   1.0 zip tar
-   0.6 zip tar
-   0.5 zip tar
-   0.4.2 zip tar
-   0.4.1 zip tar
-   0.4 zip tar
-   0.3 zip tar
-   0.2.1 zip tar
-   0.2 zip tar
-   0.1.1 zip tar
-   0.1 zip tar