joshuadavidthomas / django-hosts

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

Home Page:http://django-hosts.rtfd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-hosts

image

image

image

image

image

image

image

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:

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.

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

  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.

About

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

http://django-hosts.rtfd.org

License:Other


Languages

Language:Python 99.6%Language:Makefile 0.4%