當前位置: 首頁>>代碼示例>>Python>>正文


Python request.split_domain_port方法代碼示例

本文整理匯總了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 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:12,代碼來源:model_utils.py

示例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 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:12,代碼來源:models.py

示例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] 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:17,代碼來源:models.py

示例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 
開發者ID:limpbrains,項目名稱:django-cc,代碼行數:11,代碼來源:views.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:6,代碼來源:tests.py

示例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) 
開發者ID:overshard,項目名稱:timestrap,代碼行數:14,代碼來源:site.py


注:本文中的django.http.request.split_domain_port方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。