Registry / devops / django-subdomains

django-subdomains

JSON →
library3.0.1pypypiunverified

Subdomain tools for the Django framework, including subdomain-based URL routing. Version 3.0.1 is current. Releases are intermittent, mainly bug fixes.

pip install django-subdomains==3.0.1
INSTALL
IMPORT
SIG · DJANGO-SUBDOMAINS
D
django-subdomains
devopspythonv3.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SubdomainURLMiddleware
from subdomains.middleware import SubdomainURLMiddleware
from subdomains.middleware import SubdomainMiddleware
Renamed in v3.0.0; old name removed.
subdomain_urls
from subdomains.urls import subdomain_urls
from subdomains import subdomain_urls
Changed import path in v3.0.0.

Basic setup: install app, add middleware, define SUBDOMAIN_URLCONFS.

# settings.py INSTALLED_APPS = [ ... 'subdomains', ] MIDDLEWARE = [ ... 'subdomains.middleware.SubdomainURLMiddleware', ] # Define root URLconf for subdomains ROOT_URLCONF = 'project.urls' SUBDOMAIN_URLCONFS = { 'api': 'api.urls', 'www': 'project.urls', } # Example usage in urls.py (project/urls.py) from django.urls import path, include from subdomains.urls import subdomain_urls urlpatterns = [ path('admin/', admin.site.urls), ] # api/urls.py from django.urls import path from . import views urlpatterns = [ path('data/', views.data_list), ]
Debug
Known issues
breakingv3.0.0 removed the old middleware class 'SubdomainMiddleware' and changed the import paths. Update to 'SubdomainURLMiddleware' and use new import paths.
fix
Change middleware class to 'SubdomainURLMiddleware' and update imports to 'from subdomains.middleware import SubdomainURLMiddleware'.
affects: <3.0.0
gotchaThe SUBDOMAIN_URLCONFS dictionary keys must be the exact subdomain (without the parent domain). For example, for 'api.example.com' use 'api', not 'api.example.com'.
fix
Use only the subdomain label as key, e.g., 'api' or 'www'.
affects: all
deprecatedThe 'subdomain_urls' function is deprecated in favor of using standard Django URL includes inside the SUBDOMAIN_URLCONFS pattern. It still works but will be removed in future.
fix
Remove the use of 'subdomain_urls' and instead put the subdomain URL patterns directly in the referenced URLconf files.
affects: 3.x
Upgrade
Version history
3.0.1latest on PyPI
Audit
Dependencies
DjangorequiredRequired; the library is a Django app.
Agent activity
12 hits · last 30 days
node
12
Resources
django-subdomains — pip install django-subdomains · libregistry