django-hosts 1.2

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.
<object data="https://img.shields.io/pypi/v/django-hosts.svg" type="image/svg+xml">https://img.shields.io/pypi/v/django-hosts.svg</object> <object data="https://img.shields.io/travis/jezdez/django-hosts.svg" type="image/svg+xml">https://img.shields.io/travis/jezdez/django-hosts.svg</object> <object data="https://img.shields.io/coveralls/jezdez/django-hosts.svg" type="image/svg+xml">https://img.shields.io/coveralls/jezdez/django-hosts.svg</object>

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.

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.

from django_hosts import patterns, host

host_patterns = patterns('',
    host(r'(foo|bar)', 'path.to.urls', name='foo-or-bar'),
)

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:

  1. Add 'django_hosts' to your INSTALLED_APPS setting.

  2. Add 'django_hosts.middleware.HostsRequestMiddleware' to the beginning of your MIDDLEWARE_CLASSES setting.

  3. Add 'django_hosts.middleware.HostsResponseMiddleware' to the end of your MIDDLEWARE_CLASSES setting.

  4. Create a new module containing your default host patterns, e.g. in the hosts.py file next to your urls.py.

  5. Set the ROOT_HOSTCONF setting to the dotted Python import path of the module containing your host patterns, e.g.:

    ROOT_HOSTCONF = 'mysite.hosts'
    
  6. 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.

BSD

Author

Jannis Leidel

Pip

django-hosts==1.2

Classifiers

  • Development Status :: 5 - Production/Stable
  • Environment :: Web Environment
  • Framework :: Django
  • Intended Audience :: Developers
  • Operating System :: OS Independent
  • Programming Language :: Python
  • Programming Language :: Python :: 2
  • Programming Language :: Python :: 2.7
  • Programming Language :: Python :: 3
  • Programming Language :: Python :: 3.2
  • Programming Language :: Python :: 3.3
  • Programming Language :: Python :: 3.4
  • License :: OSI Approved :: BSD License
File Type Python Version Uploaded On Downloads
django_hosts-1.2-py2.py3-none-any.whl Wheel py2.py3 May 6, 2015 2,804
django-hosts-1.2.tar.gz Source May 6, 2015 1,565
Version Release Date
1.2 May 6, 2015
1.1 Jan. 5, 2015
1.0 Dec. 29, 2014
0.6 June 17, 2013
0.5 Aug. 29, 2012
0.4.2 Feb. 14, 2012
0.4.1 Dec. 23, 2011
0.4 Nov. 4, 2011
0.3 Sept. 30, 2011
0.2.1 May 31, 2011
0.2 May 31, 2011
0.1.1 May 30, 2011
0.1 May 29, 2011
Date Package Version Action
Aug. 26, 2015, 12:13 a.m. django-hosts 0.4.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.1.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.4.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.2.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.6 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.4 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.5 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.3 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 0.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 1.2 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 1.1 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts 1.0 Release Created
Aug. 26, 2015, 12:13 a.m. django-hosts Package Created