django-subdomains
django-subdomains copied to clipboard
Empty string '' for subdomain
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!
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.
@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.
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).
@jbmmhk didn't thought about SafeString
. Thanks for the explanation!