django-subdomains icon indicating copy to clipboard operation
django-subdomains copied to clipboard

Empty string '' for subdomain

Open prokaktus opened this issue 8 years ago • 4 comments

Hello!

I have the question about reverse function.

reverse have following check:

    domain = get_domain()
    if subdomain is not None:
        domain = '%s.%s' % (subdomain, domain)

But if subdomain is empty string (''), then we get domain equals to .examle.org, what completely doesn't have sense.

So maybe changing check to

    domain = get_domain()
    if subdomain:
        domain = '%s.%s' % (subdomain, domain)

will be better? If subdomain is empty string, then we use main domain. Everyone is happy!

In my code I add subdomains dynamically and sometimes I need to reverse them. Empty subdomain is my main page and I want to resolve it to main domain.

Thanks!

prokaktus avatar Jun 21 '16 15:06 prokaktus

I believe that this is the issue that I ran into. It is fixed by pull request #54. The issue is that there is a check:

if subdomain is '':

which I changed to:

if subdomain == '':

since the object 'subdomain' is a Django class, rather than a plain string.

its-jman avatar Jun 24 '16 04:06 its-jman

@jbmmhk Looks like slightly different issues. But your fix looks absolutely reasonable for me and I hope that @tkaemming will merge it eventually.

the object 'subdomain' is a Django class, rather than a plain string.

Not exactly. If you look there https://github.com/tkaemming/django-subdomains/blob/master/subdomains/middleware.py#L39 request.subdomain contains string from matched regexp.

prokaktus avatar Jun 24 '16 10:06 prokaktus

You are correct that the issue is separate from mine, the issue that I ran into was in regards to the reverse template tag. (In which case the 'subdomain' string is a SafeString from Django).

its-jman avatar Jun 24 '16 12:06 its-jman

@jbmmhk didn't thought about SafeString. Thanks for the explanation!

prokaktus avatar Jun 24 '16 12:06 prokaktus