mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-30 01:46:24 +01:00
parent
5158ee7aad
commit
6fde6863c5
@ -108,13 +108,18 @@ class Site(models.Model):
|
|||||||
still be routed to a different hostname which is set as the default
|
still be routed to a different hostname which is set as the default
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
hostname = request.META['HTTP_HOST'].split(':')[0] # KeyError here goes to the final except clause
|
hostname = request.get_host().split(':')[0]
|
||||||
try:
|
try:
|
||||||
# find a Site matching this specific hostname
|
# find a Site matching this specific hostname
|
||||||
return Site.objects.get(hostname=hostname) # Site.DoesNotExist here goes to the final except clause
|
return Site.objects.get(hostname=hostname) # Site.DoesNotExist here goes to the final except clause
|
||||||
except Site.MultipleObjectsReturned:
|
except Site.MultipleObjectsReturned:
|
||||||
# as there were more than one, try matching by port too
|
# as there were more than one, try matching by port too
|
||||||
port = request.META['SERVER_PORT'] # KeyError here goes to the final except clause
|
try:
|
||||||
|
port = request.get_port()
|
||||||
|
except AttributeError:
|
||||||
|
# Request.get_port is Django 1.9+
|
||||||
|
# KeyError here falls out below
|
||||||
|
port = request.META['SERVER_PORT']
|
||||||
return Site.objects.get(hostname=hostname, port=int(port))
|
return Site.objects.get(hostname=hostname, port=int(port))
|
||||||
# Site.DoesNotExist here goes to the final except clause
|
# Site.DoesNotExist here goes to the final except clause
|
||||||
except (Site.DoesNotExist, KeyError):
|
except (Site.DoesNotExist, KeyError):
|
||||||
|
Loading…
Reference in New Issue
Block a user