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


Python settings.ALLOWED_HOSTS屬性代碼示例

本文整理匯總了Python中django.conf.settings.ALLOWED_HOSTS屬性的典型用法代碼示例。如果您正苦於以下問題:Python settings.ALLOWED_HOSTS屬性的具體用法?Python settings.ALLOWED_HOSTS怎麽用?Python settings.ALLOWED_HOSTS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在django.conf.settings的用法示例。


在下文中一共展示了settings.ALLOWED_HOSTS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: setup_test_environment

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def setup_test_environment():
    """Perform any global pre-test setup. This involves:

        - Installing the instrumented test renderer
        - Set the email backend to the locmem email backend.
        - Setting the active locale to match the LANGUAGE_CODE setting.
    """
    Template._original_render = Template._render
    Template._render = instrumented_test_render

    # Storing previous values in the settings module itself is problematic.
    # Store them in arbitrary (but related) modules instead. See #20636.

    mail._original_email_backend = settings.EMAIL_BACKEND
    settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'

    request._original_allowed_hosts = settings.ALLOWED_HOSTS
    settings.ALLOWED_HOSTS = ['*']

    mail.outbox = []

    deactivate() 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:24,代碼來源:utils.py

示例2: teardown_test_environment

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def teardown_test_environment():
    """Perform any global post-test teardown. This involves:

        - Restoring the original test renderer
        - Restoring the email sending functions

    """
    Template._render = Template._original_render
    del Template._original_render

    settings.EMAIL_BACKEND = mail._original_email_backend
    del mail._original_email_backend

    settings.ALLOWED_HOSTS = request._original_allowed_hosts
    del request._original_allowed_hosts

    del mail.outbox 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:19,代碼來源:utils.py

示例3: get_host

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def get_host(self):
        """Return the HTTP host using the environment or request headers."""
        host = self._get_raw_host()

        # Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.
        allowed_hosts = settings.ALLOWED_HOSTS
        if settings.DEBUG and not allowed_hosts:
            allowed_hosts = ['localhost', '127.0.0.1', '[::1]']

        domain, port = split_domain_port(host)
        if domain and validate_host(domain, allowed_hosts):
            return host
        else:
            msg = "Invalid HTTP_HOST header: %r." % host
            if domain:
                msg += " You may need to add %r to ALLOWED_HOSTS." % domain
            else:
                msg += " The domain name provided is not valid according to RFC 1034/1035."
            raise DisallowedHost(msg) 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:21,代碼來源:request.py

示例4: domain

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def domain(context, url=''):
    if 'request' in context:
        protocol = 'https' if context['request'].is_secure() else 'http'
        _domain = get_current_site(context['request']).domain
    elif 'protocol' in context and 'domain' in context:
        # Django emails
        protocol, _domain = context['protocol'], context['domain']
    elif 'site' in context:
        # Postman emails
        _domain = context['site'].domain
        protocol = 'https' if 'pasportaservo.org' in _domain else 'http'
    else:
        # Fallback
        if settings.DEBUG:
            protocol, _domain = 'http', 'localhost:8000'
        else:
            protocol, _domain = 'https', settings.ALLOWED_HOSTS[0]

    link = '{}://{}{}'.format(protocol, _domain, url)
    return link 
開發者ID:tejoesperanto,項目名稱:pasportaservo,代碼行數:22,代碼來源:domain.py

示例5: get_host

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def get_host(self):
        """Returns the HTTP host using the environment or request headers."""
        # We try three options, in order of decreasing preference.
        if settings.USE_X_FORWARDED_HOST and (
            'HTTP_X_FORWARDED_HOST' in self.META):
            host = self.META['HTTP_X_FORWARDED_HOST']
        elif 'HTTP_HOST' in self.META:
            host = self.META['HTTP_HOST']
        else:
            # Reconstruct the host using the algorithm from PEP 333.
            host = self.META['SERVER_NAME']
            server_port = str(self.META['SERVER_PORT'])
            if server_port != ('443' if self.is_secure() else '80'):
                host = '%s:%s' % (host, server_port)

        allowed_hosts = ['*'] if settings.DEBUG else settings.ALLOWED_HOSTS
        if validate_host(host, allowed_hosts):
            return host
        else:
            raise SuspiciousOperation(
                "Invalid HTTP_HOST header (you may need to set ALLOWED_HOSTS): %s" % host) 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:23,代碼來源:request.py

示例6: get_host

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def get_host(self):
        """Return the HTTP host using the environment or request headers."""
        host = self._get_raw_host()

        # There is no hostname validation when DEBUG=True
        if settings.DEBUG:
            return host

        domain, port = split_domain_port(host)
        if domain and validate_host(domain, settings.ALLOWED_HOSTS):
            return host
        else:
            msg = "Invalid HTTP_HOST header: %r." % host
            if domain:
                msg += " You may need to add %r to ALLOWED_HOSTS." % domain
            else:
                msg += " The domain name provided is not valid according to RFC 1034/1035."
            raise DisallowedHost(msg) 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:20,代碼來源:request.py

示例7: teardown_test_environment

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def teardown_test_environment():
    """Perform any global post-test teardown. This involves:

        - Restoring the original test renderer
        - Restoring the email sending functions
    """
    Template._render = Template._original_render
    del Template._original_render

    settings.EMAIL_BACKEND = mail._original_email_backend
    del mail._original_email_backend

    settings.ALLOWED_HOSTS = request._original_allowed_hosts
    del request._original_allowed_hosts

    del mail.outbox 
開發者ID:drexly,項目名稱:openhgsenti,代碼行數:18,代碼來源:utils.py

示例8: get_host

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def get_host(self):
        """Returns the HTTP host using the environment or request headers."""
        # We try three options, in order of decreasing preference.
        if settings.USE_X_FORWARDED_HOST and (
                'HTTP_X_FORWARDED_HOST' in self.META):
            host = self.META['HTTP_X_FORWARDED_HOST']
        elif 'HTTP_HOST' in self.META:
            host = self.META['HTTP_HOST']
        else:
            # Reconstruct the host using the algorithm from PEP 333.
            host = self.META['SERVER_NAME']
            server_port = str(self.META['SERVER_PORT'])
            if server_port != ('443' if self.is_secure() else '80'):
                host = '%s:%s' % (host, server_port)

        # There is no hostname validation when DEBUG=True
        if settings.DEBUG:
            return host

        domain, port = split_domain_port(host)
        if domain and validate_host(domain, settings.ALLOWED_HOSTS):
            return host
        else:
            msg = "Invalid HTTP_HOST header: %r." % host
            if domain:
                msg += " You may need to add %r to ALLOWED_HOSTS." % domain
            else:
                msg += " The domain name provided is not valid according to RFC 1034/1035."
            raise DisallowedHost(msg) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:31,代碼來源:request.py

示例9: handle

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def handle(self, *args, **options):
        from django.conf import settings

        if not settings.DEBUG and not settings.ALLOWED_HOSTS:
            raise CommandError('You must set settings.ALLOWED_HOSTS if DEBUG is False.')

        self.use_ipv6 = options.get('use_ipv6')
        if self.use_ipv6 and not socket.has_ipv6:
            raise CommandError('Your Python does not support IPv6.')
        self._raw_ipv6 = False
        if not options.get('addrport'):
            self.addr = ''
            self.port = DEFAULT_PORT
        else:
            m = re.match(naiveip_re, options['addrport'])
            if m is None:
                raise CommandError('"%s" is not a valid port number '
                                   'or address:port pair.' % options['addrport'])
            self.addr, _ipv4, _ipv6, _fqdn, self.port = m.groups()
            if not self.port.isdigit():
                raise CommandError("%r is not a valid port number." % self.port)
            if self.addr:
                if _ipv6:
                    self.addr = self.addr[1:-1]
                    self.use_ipv6 = True
                    self._raw_ipv6 = True
                elif self.use_ipv6 and not _fqdn:
                    raise CommandError('"%s" is not a valid IPv6 address.' % self.addr)
        if not self.addr:
            self.addr = '::1' if self.use_ipv6 else '127.0.0.1'
            self._raw_ipv6 = bool(self.use_ipv6)
        self.run(**options) 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:34,代碼來源:runserver.py

示例10: setup_test_environment

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def setup_test_environment(debug=None):
    """
    Perform global pre-test setup, such as installing the instrumented template
    renderer and setting the email backend to the locmem email backend.
    """
    if hasattr(_TestState, 'saved_data'):
        # Executing this function twice would overwrite the saved values.
        raise RuntimeError(
            "setup_test_environment() was already called and can't be called "
            "again without first calling teardown_test_environment()."
        )

    if debug is None:
        debug = settings.DEBUG

    saved_data = SimpleNamespace()
    _TestState.saved_data = saved_data

    saved_data.allowed_hosts = settings.ALLOWED_HOSTS
    # Add the default host of the test client.
    settings.ALLOWED_HOSTS = list(settings.ALLOWED_HOSTS) + ['testserver']

    saved_data.debug = settings.DEBUG
    settings.DEBUG = debug

    saved_data.email_backend = settings.EMAIL_BACKEND
    settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'

    saved_data.template_render = Template._render
    Template._render = instrumented_test_render

    mail.outbox = []

    deactivate() 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:36,代碼來源:utils.py

示例11: teardown_test_environment

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def teardown_test_environment():
    """
    Perform any global post-test teardown, such as restoring the original
    template renderer and restoring the email sending functions.
    """
    saved_data = _TestState.saved_data

    settings.ALLOWED_HOSTS = saved_data.allowed_hosts
    settings.DEBUG = saved_data.debug
    settings.EMAIL_BACKEND = saved_data.email_backend
    Template._render = saved_data.template_render

    del _TestState.saved_data
    del mail.outbox 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:16,代碼來源:utils.py

示例12: setUpClass

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def setUpClass(cls):
        super().setUpClass()
        connections_override = {}
        for conn in connections.all():
            # If using in-memory sqlite databases, pass the connections to
            # the server thread.
            if conn.vendor == 'sqlite' and conn.is_in_memory_db():
                # Explicitly enable thread-shareability for this connection
                conn.allow_thread_sharing = True
                connections_override[conn.alias] = conn

        cls._live_server_modified_settings = modify_settings(
            ALLOWED_HOSTS={'append': cls.host},
        )
        cls._live_server_modified_settings.enable()
        cls.server_thread = cls._create_server_thread(connections_override)
        cls.server_thread.daemon = True
        cls.server_thread.start()

        # Wait for the live server to be ready
        cls.server_thread.is_ready.wait()
        if cls.server_thread.error:
            # Clean up behind ourselves, since tearDownClass won't get called in
            # case of errors.
            cls._tearDownClassInternal()
            raise cls.server_thread.error 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:28,代碼來源:testcases.py

示例13: AllowedHostsAndFileOriginValidator

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def AllowedHostsAndFileOriginValidator(application):
    # copied from channels.security.websocket
    allowed_hosts = settings.ALLOWED_HOSTS
    if settings.DEBUG and not allowed_hosts:
        allowed_hosts = ["localhost", "127.0.0.1", "[::1]"]
    return OriginValidatorThatAllowsFileUrls(application, allowed_hosts) 
開發者ID:yunity,項目名稱:karrot-backend,代碼行數:8,代碼來源:routing.py

示例14: setUpClass

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def setUpClass(cls):
        settings.TENANT_MODEL = 'customers.Client'
        settings.TENANT_DOMAIN_MODEL = 'customers.Domain'
        settings.SHARED_APPS = ('django_tenants',
                                'customers')
        settings.TENANT_APPS = ('dts_test_app',
                                'django.contrib.contenttypes',
                                'django.contrib.auth', )
        settings.INSTALLED_APPS = settings.SHARED_APPS + settings.TENANT_APPS
        if '.test.com' not in settings.ALLOWED_HOSTS:
            settings.ALLOWED_HOSTS += ['.test.com']
        cls.available_apps = settings.INSTALLED_APPS

        super().setUpClass() 
開發者ID:django-tenants,項目名稱:django-tenants,代碼行數:16,代碼來源:testcases.py

示例15: tearDownClass

# 需要導入模塊: from django.conf import settings [as 別名]
# 或者: from django.conf.settings import ALLOWED_HOSTS [as 別名]
def tearDownClass(cls):
        super().tearDownClass()
        if '.test.com' in settings.ALLOWED_HOSTS:
            settings.ALLOWED_HOSTS.remove('.test.com') 
開發者ID:django-tenants,項目名稱:django-tenants,代碼行數:6,代碼來源:testcases.py


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