本文整理匯總了Python中django.http.request.split_domain_port方法的典型用法代碼示例。如果您正苦於以下問題:Python request.split_domain_port方法的具體用法?Python request.split_domain_port怎麽用?Python request.split_domain_port使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.http.request
的用法示例。
在下文中一共展示了request.split_domain_port方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_by_request
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def get_by_request(cls, request):
domain = request.get_host()
# Lookup by domain with/without port
try:
obj = cls.objects.get(domain=domain)
except cls.DoesNotExist:
# Lookup without port
domain, _port = split_domain_port(domain)
obj = cls.objects.get(domain=domain)
return obj
示例2: _find_for_request
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def _find_for_request(request):
hostname = split_domain_port(request.get_host())[0]
port = request.get_port()
site = None
try:
site = get_site_for_hostname(hostname, port)
except Site.DoesNotExist:
pass
# copy old SiteMiddleware behavior
return site
示例3: _get_site_by_request
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def _get_site_by_request(self, request):
host = request.get_host()
try:
# First attempt to look up the site by host with or without port.
if host not in SITE_CACHE:
SITE_CACHE[host] = self.get(domain__iexact=host)
return SITE_CACHE[host]
except Site.DoesNotExist:
# Fallback to looking up site after stripping port from the host.
domain, port = split_domain_port(host)
if not port:
raise
if domain not in SITE_CACHE:
SITE_CACHE[domain] = self.get(domain__iexact=domain)
return SITE_CACHE[domain]
示例4: cc_validate_host
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def cc_validate_host(func):
def validate(request):
domain, port = split_domain_port(request.META['HTTP_HOST'])
if not validate_host(domain, settings.CC_ALLOWED_HOSTS):
return HttpResponseForbidden('forbiden')
return func(request)
return validate
示例5: test_split_domain_port_removes_trailing_dot
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def test_split_domain_port_removes_trailing_dot(self):
domain, port = split_domain_port('example.com.:8080')
self.assertEqual(domain, 'example.com')
self.assertEqual(port, '8080')
示例6: __call__
# 需要導入模塊: from django.http import request [as 別名]
# 或者: from django.http.request import split_domain_port [as 別名]
def __call__(self, request):
domain, port = split_domain_port(request.get_host())
try:
current_site = Site.objects.get(domain=domain)
except Site.DoesNotExist:
current_site = Site.objects.get(id=settings.SITE_ID)
request.site = current_site
_thread_local.request = request
return self.get_response(request)