A Django middleware module to handle multiple domains.
Project description
dj-multidomain
Multiple Domain Middleware for Django
This middleware allows Django projects to route requests to different URL configurations based on the request's domain. It is especially useful for projects hosted on multiple domains. Developed by Ferhat Mousavi.
Supported (tested) Versions
- Python: 3.10 and above
- Django: 4 and above
Installation
- Install the package using pip:
pip install dj-multidomain
- Add the Middleware to your Django settings:
MIDDLEWARE = [
...
'dj-multidomain.middleware.MultipleDomainMiddleware',
...
]
- Configure the domains and their associated URL configurations in settings.py using the MULTI_DOMAIN_CONFIG setting:
MULTI_DOMAIN_CONFIG = {
'domain1.com': 'path.to.urls_for_domain1',
'domain2.com': 'path.to.urls_for_domain2',
...
}
sample path.to.urls_for_domain1
file
from django.urls import path, include
urlpatterns = [
path('', include('domain1_app.urls')),
]
- (Optional) For common URLs accessible from any domain, specify the COMMON_URLS setting:
COMMON_URLS = 'path.to.common_urls'
sample path.to.common_urls
file
from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
]
- (Optional) If you are in DEBUG mode and want a fallback for unrecognized domains, specify the DEFAULT_DOMAIN setting:
DEFAULT_DOMAIN = 'path.to.default_urls'
Usage
With the middleware set up, incoming requests will be routed based on their domain to the specified URL configurations. URLs defined in COMMON_URLS will be accessible from any domain.
Support & Contribution
For issues, feedback, or feature requests, please open an issue on the GitHub repository. Contributions are welcome; feel free to submit a pull request.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for dj_multidomain-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b2161b830e46980bb1cf41bf22f7ffa28c8ae740b784c59933b8d5339d65bf7 |
|
MD5 | afb7853383e385b140a20f2f4d37c2a6 |
|
BLAKE2b-256 | cc931a5be1bbd4324a7e4945e08325504f2f561d1ee665e75051c01d54e27c11 |