Proposed middleware: SubdomainURLsMiddleware
|Reported by:||Owned by:||nobody|
|Severity:||Normal||Keywords:||enhancement proposal subdomain domain urlconf|
|Cc:||drackett@…||Triage Stage:||Design decision needed|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I'm developing an application and want to support subdomains. What I had in mind was the ability to support different views depending on the subdomain hit. Essentially, what it comes down to is I want the ability to support separate URL configurations (and thus views) for certain subdomains (known ahead of time). For example, I may have a mobile.mysite.com, where the 'mobile' subdomain deals with urls/views meant for mobile phones.
I noticed issue #4438, and it wasn't exactly what I wanted, or the right solution, so I started researching.
I noticed that in BaseHandler::get_response it attempts to get the 'urlconf' attribute from the request. So, I created a middleware that figures out the subdomain (some code borrowed from http://www.rossp.org/blog/2007/apr/28/using-subdomains-django/), and matches it against a subdomain->urlconf dictionary in settings.py. And voila! It works! Attached is the file that with the proposed solution.
I am open for critiques/discussion of this topic.