Monday, June 4, 2018

Re: Sponsor subdomain pointing to part of our Django site?

On maandag 4 juni 2018 13:26:24 CEST Richard Brockie wrote:

 

> However, I'm pretty sure that we will need to make some changes to our

> project to deal with links when the site is being accessed through

> "subdomain.sponsor.url/". You are correct that {% url %} is used in the

> templates as well as django.core.urlresolvers.reverse() being used in the

> code. However, I think we need to catch the case where url or reverse() are

> returning "site.url/year/slug/some/more/path/" and convert it to

> "subdomain.sponsor.url/some/more/path/" based on the http_host in the

> request.

>

> I'm wondering if this is a solved problem?

 

This isn't a problem. Neither url nor reverse is capable of returning URLs with hostnames, at least not that I'm aware of. Only django.contrib.site module can do this for out-of-band communications.

 

So if you're encountering such cases, then you're using custom or 3rd party code or have a hardcoded hostname in your templates or are using the site module.

 

There is no magic case where reverse or the url template tag decides to add a hostname, because it senses you want it. And if you just want to serve the exact same site on a different domain, then ALLOWED_HOSTS is all you need.

 

If you want to brand the site with a different look and feel, then you will need the site module, because then you will serve different content.

 

If you're asking "how can i be sure there are no mistakes in our code", then you should already know the answer - test, test, test :).

--

Melvyn Sopacua

No comments:

Post a Comment