Skip to main content

Djano Subdomain Middleware

The Django subdomain middleware provides the ability to configure different url configurations for each subdomain.

How To Install

This package can be installed using Pip. Prior to doing so however you should identify the version that you require.

The versioning of this package matches the versioning of Django. Therefore, if you are using Django 4.2 you should use version 4.2 of this package.

Once you have identified the version you can simply do something along the lines of:

pip install django_subdomain_middleware>=4.2,<5

How To Use

To use this package simple do the following:

Add django_subdomain_middleware To The Middleware

Within settings.py there will be a list assigned to the MIDDLEWARE constant. Add the following to it after common:

"django_subdomain_middleware.subdomain.Subdomain",

so that it looks like:

MIDDLEWARE = [
    "django.middleware.security.SecurityMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.common.CommonMiddleware",
    "django_subdomain_middleware.subdomain.Subdomain",
    "django.middleware.csrf.CsrfViewMiddleware",
    "django.contrib.auth.middleware.AuthenticationMiddleware",
    "django.contrib.messages.middleware.MessageMiddleware",
    "django.middleware.clickjacking.XFrameOptionsMiddleware",
]

Doing this will provide a subdomain entry in any request object.

Add Subdomain Routing

If you would like to route based on the subdomain then the following should also be carried out:

SUBDOMAIN_URL_CONF = {
    'test': "project_name.testurls",
    '*': "project_name.wildcardurls",
}

In the above example test.domain.com would use the url configuration called testurls in project_name, * acts as a wildcard, therefore, any other subdomain will be routed towards the url configuration called wildcardurls.

In the event that either of the following occurs the standard default url configuration will be used:

  • A subdomain is visited but no configuration or wildcard exists.
  • A visitor goes directly to the allowed hosts domain.

Metadata

Release files for Django-Subdomain-Middleware 4.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Django-Subdomain-Middleware 4.2.0
File Size Uploaded
Django Subdomain Middleware-4.2.0.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Django-Subdomain-Middleware 4.2.0
File Interpreter ABI Platform
Django_Subdomain_Middleware-4.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / Django Subdomain Middleware-4.2.0.tar.gz

Download URL Django Subdomain Middleware-4.2.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
61478ef0c78e3afb8d7500eebd11a9e14100fece27de3d0a33e03431928f7481
BLAKE2b-256 checksum
How to use checksums
16cc711887bf9cbbefbf89cfe45661cab062e40985fd38a4850449480934035a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / Django_Subdomain_Middleware-4.2.0-py3-none-any.whl

Download URL Django_Subdomain_Middleware-4.2.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a507f4758981158f1cbbe1c019151926b9d8b424920739145c533cab8bea6942
BLAKE2b-256 checksum
How to use checksums
2052abb25fa3145aafc506b881178b12c2be0e32477e80a4b3303cca18cf8c90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

4.2.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page