python - Django Subdomains - Web page has a redirect loop -


i developing django app users intend each user have own custom subdomain. intend use middleware purpose. far, got, on accessing site (on google chrome), redirect loop error:

class subdomainmiddleware(object):      def process_request(self, request):         if request.user.is_authenticated():             if request.company none:                 company_subdomain = request.user.company.company_url             else:                 company_subdomain = request.company.company_url             company_subdomain = company_subdomain.lower()             domain_parts = request.get_host().split('.')             if len(domain_parts) > 2:                 if domain_parts[0].lower() != company_subdomain:                     domain_parts[0] = company_subdomain             else:                 domain_parts.insert(0, company_subdomain)             domain = '.'.join(domain_parts)             return httpresponseredirect('http://' + domain + request.get_full_path())         else:             pass 

what i'm doing wrong?

your first redirect correct, redirect again though on right domain. results in redirect loop. need check if current subdomain matches intended subdomain, , if does, return none instead of redirect:

if len(domain_parts) > 2:     if domain_parts[0].lower() != company_subdomain:         domain_parts[0] = company_subdomain     else:  # subdomain matches, return instead of redirect         return none else:     domain_parts.insert(0, company_subdomain) 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -