diff options
| author | Bobby <[email protected]> | 2022-10-03 07:13:44 -0400 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-10-03 07:13:44 -0400 |
| commit | 4f3e61f433b6a4f50eb23072dd8540fa5e4b9fb0 (patch) | |
| tree | 945c8a6df8bf14d19c6badb087384d8ab43f1980 | |
| parent | d2c7db1acc2188ef0d1711c9d80cf307812742a0 (diff) | |
| download | thatcomputerscientist-4f3e61f433b6a4f50eb23072dd8540fa5e4b9fb0.tar.xz thatcomputerscientist-4f3e61f433b6a4f50eb23072dd8540fa5e4b9fb0.zip | |
better subdomain routing
| -rw-r--r-- | middleware/subdomainmiddleware.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/middleware/subdomainmiddleware.py b/middleware/subdomainmiddleware.py index 73807017..479c74d6 100644 --- a/middleware/subdomainmiddleware.py +++ b/middleware/subdomainmiddleware.py @@ -8,8 +8,10 @@ class SubdomainMiddleware: request.subdomain = None host = request.get_host() host = host.replace('www.', '').split('.') - if len(host) > 2: + if len(host) > 2 and '127.0.0.1' not in request.get_host(): request.subdomain = '.'.join(host[:-2]) + if len(host) == 2 and 'localhost' in request.get_host(): + request.subdomain = host[0] return self.get_response(request) # Use different urlpatterns for each subdomain |
