--- id: django-hosts version: "7.0.0" license: BSD license_treatment: permissive maintenance: active --- # django-hosts — Dynamic and static host resolving for Django. Maps hostnames to URLconfs. License: permissive · Maintenance: active · Downloads: 397.7K/mo ## 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 above — 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 pip install django-hosts uv add django-hosts 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_current - Install friction: low - Maintenance: active - Downloads: 397.7K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django subdomain routing, multi-host django, hostname-based url routing, django virtual hosts, subdomain url configuration, django request routing by host, dynamic host resolution django, django-middleware, subdomain-routing, multi-tenant [View on SkillFed](https://skillfed.io/packages/django-hosts) · [View on PyPI](https://pypi.org/project/django-hosts/)