# 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:
```bash
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:
```python
"django_subdomain_middleware.subdomain.Subdomain",
```
so that it looks like:
```python
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:
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/RockProfile/django-subdomain-middleware",
"name": "Django-Subdomain-Middleware",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Peter McDonald",
"author_email": "git@petermcdonald.co.uk",
"download_url": "https://files.pythonhosted.org/packages/16/cc/711887bf9cbbefbf89cfe45661cab062e40985fd38a4850449480934035a/Django%20Subdomain%20Middleware-4.2.0.tar.gz",
"platform": null,
"description": "# Djano Subdomain Middleware\n\nThe Django subdomain middleware provides the ability to configure\ndifferent url configurations for each subdomain.\n\n## How To Install\n\nThis package can be installed using Pip. Prior to doing so however you\nshould identify the version that you require.\n\nThe versioning of this package matches the versioning of Django.\nTherefore, if you are using Django 4.2 you should use version 4.2 of\nthis package.\n\nOnce you have identified the version you can simply do something along\nthe lines of:\n\n```bash\npip install django_subdomain_middleware>=4.2,<5\n```\n\n## How To Use\n\nTo use this package simple do the following:\n\n### Add django_subdomain_middleware To The Middleware\n\nWithin settings.py there will be a list assigned to the MIDDLEWARE\nconstant. Add the following to it after common:\n\n```python\n\"django_subdomain_middleware.subdomain.Subdomain\",\n```\n\nso that it looks like:\n\n```python\nMIDDLEWARE = [\n \"django.middleware.security.SecurityMiddleware\",\n \"django.contrib.sessions.middleware.SessionMiddleware\",\n \"django.middleware.common.CommonMiddleware\",\n \"django_subdomain_middleware.subdomain.Subdomain\",\n \"django.middleware.csrf.CsrfViewMiddleware\",\n \"django.contrib.auth.middleware.AuthenticationMiddleware\",\n \"django.contrib.messages.middleware.MessageMiddleware\",\n \"django.middleware.clickjacking.XFrameOptionsMiddleware\",\n]\n```\n\nDoing this will provide a subdomain entry in any request object.\n\n### Add Subdomain Routing\n\nIf you would like to route based on the subdomain then the following\nshould also be carried out:\n\n```python\nSUBDOMAIN_URL_CONF = {\n 'test': \"project_name.testurls\",\n '*': \"project_name.wildcardurls\",\n}\n```\n\nIn the above example test.domain.com would use the url configuration\ncalled testurls in project_name, * acts as a wildcard, therefore,\nany other subdomain will be routed towards the url configuration\ncalled wildcardurls.\n\nIn the event that either of the following occurs the standard\ndefault url configuration will be used:\n\n* A subdomain is visited but no configuration or wildcard exists.\n* A visitor goes directly to the allowed hosts domain.\n",
"bugtrack_url": null,
"license": "",
"summary": "Django middleware to handle routing for subdomains.",
"version": "4.2.0",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2052abb25fa3145aafc506b881178b12c2be0e32477e80a4b3303cca18cf8c90",
"md5": "402425405c37df9c496e168cc7c52db1",
"sha256": "a507f4758981158f1cbbe1c019151926b9d8b424920739145c533cab8bea6942"
},
"downloads": -1,
"filename": "Django_Subdomain_Middleware-4.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "402425405c37df9c496e168cc7c52db1",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 4413,
"upload_time": "2023-04-17T19:14:34",
"upload_time_iso_8601": "2023-04-17T19:14:34.832340Z",
"url": "https://files.pythonhosted.org/packages/20/52/abb25fa3145aafc506b881178b12c2be0e32477e80a4b3303cca18cf8c90/Django_Subdomain_Middleware-4.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "16cc711887bf9cbbefbf89cfe45661cab062e40985fd38a4850449480934035a",
"md5": "a352ecc036e47fa4d2b2b2e699a55b87",
"sha256": "61478ef0c78e3afb8d7500eebd11a9e14100fece27de3d0a33e03431928f7481"
},
"downloads": -1,
"filename": "Django Subdomain Middleware-4.2.0.tar.gz",
"has_sig": false,
"md5_digest": "a352ecc036e47fa4d2b2b2e699a55b87",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 3867,
"upload_time": "2023-04-17T19:14:36",
"upload_time_iso_8601": "2023-04-17T19:14:36.753266Z",
"url": "https://files.pythonhosted.org/packages/16/cc/711887bf9cbbefbf89cfe45661cab062e40985fd38a4850449480934035a/Django%20Subdomain%20Middleware-4.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-17 19:14:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "RockProfile",
"github_project": "django-subdomain-middleware",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "django-subdomain-middleware"
}