本文整理汇总了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)