(Important: this is Django 1.8)
In our site we are going to introduce a feature that would allow users who own a domain name of their own to link it to their organization id in our site. That way they can bootstrap their organization site through our tools and link different relevant pages to their domain. We’d provide default content so they have an organization page based on their organization information we already have in our site right off the bat.
Basically, using an example, if an organization admin user registers their organization with id 12345
to a domain name they specify, domain.org
, we would automatically register it in DigitalOcean and requests made to that domain should be mapped to the corresponding organization on our end as follows:
domain.org/ -> oursite.org/organization/12345
domain.org/dashboard -> oursite.org/organization/12345/dashboard
domain.org/about -> oursite.org/organizatin/12345/about
I am not sure if this is a common problem but I am not sure how to set it up. Perhaps the way to go is to set a root handler:
urlpatterns = patterns('',
(r'^$', root),
...
)
And that root
view would have the responsibility of looking up the organization id that corresponds to the URL’s domain which can be accessed with request.get_host()
.
-
is this a valid approach or typically this is done differently?
-
domain.org
should behave as if redirected tooursite.org/organization/12345
but without changing the URL. This should work like a reverse proxy, without the client knowing behind the scenesdomain.org/whatever
actually translates tooursite.org./organization/12345/whatever
. -
how can URLs be rendered using the
{% url %}
tag so that instead of our site’s domain name, the organization’s domain name is displayed? This is natural: we would want to have links todomain.org/some-page
, notoursite.org/organization/12345/some-page
. -
would these domain names need to be added to
ALLOWED_HOSTS
? Would this mean I need to restart the server every time a user registers a new domain? How do I deal with this?