Opened 8 years ago

Closed 3 years ago

#8896 closed New feature (wontfix)

Routing according also to hostname

Reported by: veena Owned by: jshedd
Component: Core (URLs) Version: 1.0
Severity: Normal Keywords: routing hostname
Cc: mike.huynh+django@…, jedie, gvangool, apollo13, cg@…, charette.s@… Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


There should be a possibility to route urls even according to hostname.

It's quite often especially in blog sites that users get 3rd domain eg.

In Django url router doesn't take hostname in consideration.

You can write own middleware, where you can rewrite to something like in process_request() function. But then function like "reverse()", decorator like "login" or template tag like "{% url %}" are not able to construct whole url with hostname back now.

In case of implementation routing with hostname there could be simple syntax in urls like that:

urlpatterns = (
  ('^forum/$', forum) # normal route
  ('^/(username)\.example\.com/forum/$', user_forum) # route with domain with http protocol
  ('^//(username)\.example\.com/forum/$', user_forum) # or syntax with double slashes to have a more impact to visibility and parallel to http://
  ('^s//(username)\.example\.com/forum/$', secure_user_forum) # route with domain with https protocol

There should be some enhancement to decouple hostname from route. For example:

  ('^//(username)\.SETTINGS_DOMAIN_WILDCARDS\.[a-zA-Z]{2-4}/forum/$', user_forum)

Or using some special mark:

  ('^//(?P<username>)(?site)/forum/$', user_forum) # complete with domain from actual Site or RequestSite object
  ('^//(?P<username>)(?site=2)/forum/$', user_forum) # complete with domain with ID 2 from Site object

In reverse functions proper url with hostname should be considered.

I think there is need to more clarify all possible circumstances they can occure before implementing of this feature would be start. It could be nice feature in 1.1 version of Django.

Change History (18)

comment:1 Changed 8 years ago by veena

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

There should be (?P<username>) instead of (username) in first two examples.

comment:2 Changed 8 years ago by adrian

  • Triage Stage changed from Unreviewed to Someday/Maybe

comment:3 Changed 8 years ago by anonymous

  • milestone post-1.0 deleted

Milestone post-1.0 deleted

comment:4 Changed 7 years ago by skip

#5034 may address this issue in that reverse() and consequently {% url %} respect the overridden urlconf.

comment:5 Changed 7 years ago by jshedd

  • milestone set to 1.2
  • Owner changed from nobody to jshedd

comment:6 Changed 7 years ago by russellm

  • milestone 1.2 deleted

comment:7 Changed 6 years ago by mikexstudios

  • Cc mike.huynh+django@… added

comment:8 Changed 6 years ago by jedie

  • Cc jedie added

comment:9 Changed 6 years ago by gvangool

  • Cc gvangool added

comment:10 Changed 6 years ago by apollo13

  • Cc apollo13 added

comment:11 Changed 5 years ago by lukeplant

  • Severity set to Normal
  • Type set to New feature

comment:12 Changed 5 years ago by EnTeQuAk

  • Cc cg@… added
  • Easy pickings unset

comment:13 Changed 5 years ago by jezdez

You might want to have a look at the django-hosts app:

comment:14 Changed 5 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:15 Changed 5 years ago by charettes

  • Cc charette.s@… added

comment:16 Changed 3 years ago by aaugustin

  • Component changed from Core (Other) to Core (URLs)

comment:17 Changed 3 years ago by aaugustin

#16139 was a duplicate.

comment:18 Changed 3 years ago by aaugustin

  • Resolution set to wontfix
  • Status changed from new to closed

This has been solved by external apps and I'm happy with that solution.

Django should remain focused on the mainstream use cases.

This one isn't unheard of, but it's hardly common.

Note: See TracTickets for help on using tickets.
Back to Top