{"id":21566479,"url":"https://github.com/ferhat-mousavi/dj-multidomain","last_synced_at":"2026-02-03T22:06:24.297Z","repository":{"id":190185427,"uuid":"682081463","full_name":"ferhat-mousavi/dj-multidomain","owner":"ferhat-mousavi","description":"This middleware enables Django projects to route requests to different URL configurations based on the domain of the incoming request.","archived":false,"fork":false,"pushed_at":"2024-12-08T04:08:21.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-28T23:42:14.132Z","etag":null,"topics":["django","django-library","django-middleware","multi-domain","multi-domain-name","python","python-3","python-library","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ferhat-mousavi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-23T11:56:12.000Z","updated_at":"2024-12-08T04:08:25.000Z","dependencies_parsed_at":"2024-08-22T01:24:33.835Z","dependency_job_id":"6c9c3416-df77-46b9-aa14-3c4f4582aeb1","html_url":"https://github.com/ferhat-mousavi/dj-multidomain","commit_stats":null,"previous_names":["ferhat-mousavi/dj-multidomain"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ferhat-mousavi/dj-multidomain","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferhat-mousavi%2Fdj-multidomain","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferhat-mousavi%2Fdj-multidomain/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferhat-mousavi%2Fdj-multidomain/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferhat-mousavi%2Fdj-multidomain/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ferhat-mousavi","download_url":"https://codeload.github.com/ferhat-mousavi/dj-multidomain/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ferhat-mousavi%2Fdj-multidomain/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29059091,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-03T20:13:53.544Z","status":"ssl_error","status_checked_at":"2026-02-03T20:13:40.507Z","response_time":96,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-library","django-middleware","multi-domain","multi-domain-name","python","python-3","python-library","python3"],"created_at":"2024-11-24T10:25:14.655Z","updated_at":"2026-02-03T22:06:24.280Z","avatar_url":"https://github.com/ferhat-mousavi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dj-multidomain\n\n## Dynamic Multi-Domain Middleware for Django\n\n`dj-multidomain` is a powerful Django middleware that enables dynamic routing of \nrequests to different URL configurations based on the domain of \nincoming requests. \nIt also supports automatic redirection for specific domains and provides \noptions for shared common URLs. \nThis middleware is ideal for projects hosted across multiple domains or \nwith subdomain-specific functionalities.\n\nDeveloped by **Ferhat Mousavi**.\n[ferhat.mousavi@gmail.com](mailto:ferhat.mousavi@gmail.com)  \n\n---\n\n## Features\n\n- **Domain-Based URL Routing**: Route requests to different URL configurations based on the domain.\n- **Subdomain Handling**: Easily manage subdomains and inject subdomain data into requests.\n- **Automatic Redirects**: Redirect specific domains to desired ones seamlessly.\n- **Shared URLs**: Define common URLs accessible across all domains.\n- **Fallback Support**: Set a default domain for unrecognized requests (DEBUG mode).\n\n---\n\n## Installation\n\n### 1. Install the Package\n\nInstall `dj-multidomain` using pip:\n\n```bash\npip install dj-multidomain\n```\n\nEnsure `publicsuffix2` is also installed:\n\n```bash\npip install publicsuffix2\n```\n\n### 2. Add Middleware\n\nIn your `settings.py`, add the middleware to the `MIDDLEWARE` list:\n\n```python\nMIDDLEWARE = [\n    ...\n    'dj_multidomain.middleware.MultipleDomainMiddleware',\n    ...\n]\n```\n\n---\n\n## Configuration\n\n### 1. Map Domains to URL Configurations\n\nUse `MULTI_DOMAIN_CONFIG` to map domains to their respective URL configuration files. Add this to `settings.py`:\n\n```python\nMULTI_DOMAIN_CONFIG = {\n    'example.com': 'project.urls_example_com',\n    'example.org': 'project.urls_example_org',\n}\n```\n\n### 2. Redirect Domains (Optional)\n\nIf you want to redirect specific domains to others, use `MULTI_REDIRECT_CONFIG`:\n\n```python\nMULTI_REDIRECT_CONFIG = {\n    'www.example.com': 'example.com',\n    'oldsite.org': 'newsite.org',\n}\n```\n\n### 3. Add Common URLs (Optional)\n\nDefine shared URLs that are accessible from any domain using `COMMON_URLS`:\n\n```python\nCOMMON_URLS = 'project.urls_common'\n```\n\n### 4. Subdomain Configuration (Optional)\n\nIf subdomain data needs to be injected into requests, use `MULTI_SUBDOMAIN_CONFIG` to define parameter names:\n\n```python\nMULTI_SUBDOMAIN_CONFIG = ['subdomain1', 'subdomain2']\n```\n\n### 5. Default Domain (Optional)\n\nSet a fallback URL configuration for unrecognized domains (only active in DEBUG mode):\n\n```python\nDEFAULT_DOMAIN = 'example.com'\n```\n\n---\n\n## Example Project Structure\n\nBelow is a typical project structure for `dj-multidomain`:\n\n```\nproject/\n├── project/\n│   ├── __init__.py\n│   ├── settings.py\n│   ├── urls_common.py\n│   ├── urls_example_com.py\n│   ├── urls_example_org.py\n│   ├── views.py\n├── manage.py\n```\n\n---\n\n## Example Usage\n\n### 1. Domain-Specific URL Configuration\n\nCreate domain-specific URL files, e.g., `urls_example_com.py`:\n\n```python\nfrom django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path('', views.home, name='home'),\n    path('about/', views.about, name='about'),\n]\n```\n\n### 2. Common URL Configuration\n\nDefine shared URLs in `urls_common.py`:\n\n```python\nfrom django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path('contact/', views.contact, name='contact'),\n]\n```\n\n### 3. Subdomain Handling\n\nSubdomains will be available as attributes in the `request` object. For example:\n\n```python\ndef subdomain_example(request):\n    subdomain1 = getattr(request, 'subdomain1', None)\n    return HttpResponse(f\"Subdomain 1: {subdomain1}\")\n```\n\n---\n\n## Sample Configuration\n\nHere’s a complete example of `settings.py` for `dj-multidomain`:\n\n```python\nMIDDLEWARE = [\n    ...\n    'dj_multidomain.middleware.MultipleDomainMiddleware',\n    ...\n]\n\nMULTI_DOMAIN_CONFIG = {\n    'example.com': 'project.urls_example_com',\n    'example.org': 'project.urls_example_org',\n}\n\nMULTI_REDIRECT_CONFIG = {\n    'www.example.com': 'example.com',\n}\n\nMULTI_SUBDOMAIN_CONFIG = ['subdomain1', 'subdomain2']\n\nCOMMON_URLS = 'project.urls_common'\n\nDEFAULT_DOMAIN = 'example.com'\n```\n\n---\n\n## Supported Versions\n\n- **Python**: 3.10 and above\n- **Django**: 4.0 and above\n\n---\n\n## Sample Project\n\nExplore a sample implementation:  \n[GitHub: dj-multidomain Example](https://github.com/ferhat-mousavi/dj-multidomain-example)\n\n---\n\n## Contribution \u0026 Support\n\n- For issues or feedback, open an issue in the [GitHub repository](https://github.com/ferhat-mousavi/dj-multidomain).\n- Contributions are welcome! Feel free to submit a pull request.\n\n---\n\n## License\n\nThis project is licensed under the [GNU General Public License v3 (GPLv3)](https://www.gnu.org/licenses/gpl-3.0.en.html).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fferhat-mousavi%2Fdj-multidomain","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fferhat-mousavi%2Fdj-multidomain","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fferhat-mousavi%2Fdj-multidomain/lists"}