skillfed

django-hosts

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

django-hosts v7.0.0 397.7K downloads/30d#6,956 on PyPI1,060
Permissive license BSD Active released

What it is and what it does

django-hosts is a Django middleware package that intercepts incoming HTTP requests and routes them to different URL configurations based on the hostname. Instead of handling multiple subdomains within a single URLconf, you define separate hostconfs—modules containing URL patterns—and map hostnames (or patterns matching hostnames) to them. Requests to api.example.com route to one URLconf, beta.example.com to another, and unmatched hosts fall back to the default ROOT_URLCONF.

The package uses regular expressions to match hostnames against patterns, evaluated in order. It requires minimal configuration: add two middleware classes to your MIDDLEWARE setting, create a hosts.py file with your host patterns, and set ROOT_HOSTCONF and DEFAULT_HOST in settings. No runtime dependencies means a lightweight addition to any Django project.

Use it for:

  • Serve an API on api.example.com with its own URL structure separate from the main site.
  • Host a beta version at beta.example.com with different views and routes than production.
  • Route multiple branded subdomains to different content or applications within one Django project.
  • Implement multi-tenant deployments where each tenant's subdomain maps to its own URL configuration.
  • Separate admin interfaces, documentation, or internal tools onto dedicated subdomains.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Routes HTTP requests to different Django URL configurations based on the requested hostname, enabling a single Django project to serve multiple subdomains with distinct URL schemes.

Yes. django-hosts is production-stable, actively maintained, has no external dependencies, and solves a common Django deployment pattern cleanly. Use it when you need to route multiple subdomains to different URL schemes within a single Django project—it's the standard tool for this task.

Install

django-hosts on PyPI

pip

pip install django-hosts

uv

uv add django-hosts

poetry

poetry add django-hosts

Installing django-hosts

Before you install

Low install friction with no runtime dependencies. Active maintenance with recent commits and a stable release cadence; supports current Python versions (3.9–3.13) and modern Django releases (4.2, 5.1, 5.2).

License in practice

BSD license is permissive, allowing commercial and private use with minimal restrictions—suitable for most projects.

Quickstart

pip install django-hosts

# In hosts.py:
from django_hosts import patterns, host

host_patterns = patterns('',
    host(r'api', 'api.urls', name='api'),
    host(r'beta', 'beta.urls', name='beta'),
)

# In settings.py:
INSTALLED_APPS = ['django_hosts', ...]
MIDDLEWARE = ['django_hosts.middleware.HostsRequestMiddleware', ...]
ROOT_HOSTCONF = 'mysite.hosts'
DEFAULT_HOST = 'api'

Package facts

License BSD (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 421 days since the last release
Last repo commit
First released
Downloads 397,715/month — #6,956 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_hosts-7.0.0-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.1Framework :: Django :: 5.2Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9

Tags

django subdomain routingmulti-host djangohostname-based url routingdjango virtual hostssubdomain url configurationdjango request routing by hostdynamic host resolution django
django-middlewaresubdomain-routingmulti-tenant

More Dynamic Content packages