diff options
| author | Bobby <[email protected]> | 2022-11-10 11:32:32 -0500 |
|---|---|---|
| committer | Bobby <[email protected]> | 2022-11-10 11:32:32 -0500 |
| commit | 188e2bd855e4166493b118f3d9e9b8a90f2a7e4a (patch) | |
| tree | 648bf8b6609caf81d60d6e8880aaa100da1bfb37 | |
| parent | 1eca4e64326c49d6fddefca5caa89695c67173b2 (diff) | |
| download | thatcomputerscientist-188e2bd855e4166493b118f3d9e9b8a90f2a7e4a.tar.xz thatcomputerscientist-188e2bd855e4166493b118f3d9e9b8a90f2a7e4a.zip | |
handling ip address
| -rw-r--r-- | middleware/subdomainmiddleware.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/middleware/subdomainmiddleware.py b/middleware/subdomainmiddleware.py index 479c74d6..b92d1e92 100644 --- a/middleware/subdomainmiddleware.py +++ b/middleware/subdomainmiddleware.py @@ -1,5 +1,5 @@ from django.conf import settings - +from django.shortcuts import redirect class SubdomainMiddleware: def __init__(self, get_response): self.get_response = get_response @@ -12,6 +12,12 @@ class SubdomainMiddleware: request.subdomain = '.'.join(host[:-2]) if len(host) == 2 and 'localhost' in request.get_host(): request.subdomain = host[0] + # check if ip address + if len(host) == 4 and all([x.isdigit() for x in host]): + # redirect to thatcomputerscientist.com + is_ssl = request.is_secure() + protocol = 'https' if is_ssl else 'http' + return redirect(f'{protocol}://thatcomputerscientist.com') return self.get_response(request) # Use different urlpatterns for each subdomain |
