Skip to content
프로젝트

소개

Django를 위한 동적 및 정적 호스트 확인 기능입니다. 호스트 이름을 URLconf에 매핑합니다.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
-1
in 1 month
-3

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

django-hosts

https://readthedocs.org/projects/django-hosts/badge/?version=latest&style=flat

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. Django looks up handler404 and handler500 in the matched host's URLconf, so add them to each one that needs custom error pages.

Patterns are evaluated in order. If no pattern matches, the request uses the URLconf of the DEFAULT_HOST pattern.

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

    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.

관련 프로젝트 살펴보기

불러오는 중…