当前位置: 首页>>代码示例>>Python>>正文


Python settings.DEFAULT_CONTENT_TYPE属性代码示例

本文整理汇总了Python中django.conf.settings.DEFAULT_CONTENT_TYPE属性的典型用法代码示例。如果您正苦于以下问题:Python settings.DEFAULT_CONTENT_TYPE属性的具体用法?Python settings.DEFAULT_CONTENT_TYPE怎么用?Python settings.DEFAULT_CONTENT_TYPE使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在django.conf.settings的用法示例。


在下文中一共展示了settings.DEFAULT_CONTENT_TYPE属性的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            self.status_code = status
        if reason is not None:
            self.reason_phrase = reason
        elif self.reason_phrase is None:
            self.reason_phrase = REASON_PHRASES.get(self.status_code,
                                                    'UNKNOWN STATUS CODE')
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:25,代码来源:response.py

示例2: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            try:
                self.status_code = int(status)
            except (ValueError, TypeError):
                raise TypeError('HTTP status code must be an integer.')

            if not 100 <= self.status_code <= 599:
                raise ValueError('HTTP status code must be an integer from 100 to 599.')
        self._reason_phrase = reason
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:27,代码来源:response.py

示例3: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def __init__(self, content_type=None, status=None, mimetype=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._charset = settings.DEFAULT_CHARSET
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        if mimetype:
            warnings.warn("Using mimetype keyword argument is deprecated, use"
                          " content_type instead", PendingDeprecationWarning)
            content_type = mimetype
        if not content_type:
            content_type = "%s; charset=%s" % (settings.DEFAULT_CONTENT_TYPE,
                    self._charset)
        self.cookies = SimpleCookie()
        if status:
            self.status_code = status

        self['Content-Type'] = content_type 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:response.py

示例4: __init__

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def __init__(self, content_type=None, status=None, reason=None, charset=None):
        # _headers is a mapping of the lower-case name to the original case of
        # the header (required for working with legacy systems) and the header
        # value. Both the name of the header and its value are ASCII strings.
        self._headers = {}
        self._closable_objects = []
        # This parameter is set by the handler. It's necessary to preserve the
        # historical behavior of request_finished.
        self._handler_class = None
        self.cookies = SimpleCookie()
        self.closed = False
        if status is not None:
            self.status_code = status
        self._reason_phrase = reason
        self._charset = charset
        if content_type is None:
            content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
                                               self.charset)
        self['Content-Type'] = content_type 
开发者ID:drexly,项目名称:openhgsenti,代码行数:21,代码来源:response.py

示例5: test_default_content_type_is_text_html

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def test_default_content_type_is_text_html(self):
        """
        Content-Type of the default error responses is text/html. Refs #20822.
        """
        with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
            response = self.client.get('/raises400/')
            self.assertEqual(response['Content-Type'], 'text/html')

            response = self.client.get('/raises403/')
            self.assertEqual(response['Content-Type'], 'text/html')

            response = self.client.get('/nonexistent_url/')
            self.assertEqual(response['Content-Type'], 'text/html')

            response = self.client.get('/server_error/')
            self.assertEqual(response['Content-Type'], 'text/html') 
开发者ID:nesdis,项目名称:djongo,代码行数:18,代码来源:test_default_content_type.py

示例6: set_headers

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def set_headers(self, filelike):
        """
        Set some common response headers (Content-Length, Content-Type, and
        Content-Disposition) based on the `filelike` response content.
        """
        encoding_map = {
            'bzip2': 'application/x-bzip',
            'gzip': 'application/gzip',
            'xz': 'application/x-xz',
        }
        filename = getattr(filelike, 'name', None)
        filename = filename if (isinstance(filename, str) and filename) else self.filename
        if os.path.isabs(filename):
            self['Content-Length'] = os.path.getsize(filelike.name)
        elif hasattr(filelike, 'getbuffer'):
            self['Content-Length'] = filelike.getbuffer().nbytes

        if self.get('Content-Type', '').startswith(settings.DEFAULT_CONTENT_TYPE):
            if filename:
                content_type, encoding = mimetypes.guess_type(filename)
                # Encoding isn't set to prevent browsers from automatically
                # uncompressing files.
                content_type = encoding_map.get(encoding, content_type)
                self['Content-Type'] = content_type or 'application/octet-stream'
            else:
                self['Content-Type'] = 'application/octet-stream'

        if self.as_attachment:
            filename = self.filename or os.path.basename(filename)
            if filename:
                try:
                    filename.encode('ascii')
                    file_expr = 'filename="{}"'.format(filename)
                except UnicodeEncodeError:
                    file_expr = "filename*=utf-8''{}".format(quote(filename))
                self['Content-Disposition'] = 'attachment; {}'.format(file_expr) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:38,代码来源:response.py

示例7: test_override_settings_warning

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def test_override_settings_warning(self):
        with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
            with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
                pass 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:test_default_content_type.py

示例8: test_settings_init_warning

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def test_settings_init_warning(self):
        settings_module = ModuleType('fake_settings_module')
        settings_module.DEFAULT_CONTENT_TYPE = 'text/xml'
        settings_module.SECRET_KEY = 'abc'
        sys.modules['fake_settings_module'] = settings_module
        try:
            with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
                Settings('fake_settings_module')
        finally:
            del sys.modules['fake_settings_module'] 
开发者ID:nesdis,项目名称:djongo,代码行数:12,代码来源:test_default_content_type.py

示例9: test_access_warning

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def test_access_warning(self):
        with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
            settings.DEFAULT_CONTENT_TYPE
        # Works a second time.
        with self.assertRaisesMessage(RemovedInDjango30Warning, self.msg):
            settings.DEFAULT_CONTENT_TYPE 
开发者ID:nesdis,项目名称:djongo,代码行数:8,代码来源:test_default_content_type.py

示例10: test_access

# 需要导入模块: from django.conf import settings [as 别名]
# 或者: from django.conf.settings import DEFAULT_CONTENT_TYPE [as 别名]
def test_access(self):
        with self.settings(DEFAULT_CONTENT_TYPE='text/xml'):
            self.assertEqual(settings.DEFAULT_CONTENT_TYPE, 'text/xml')
            # Works a second time.
            self.assertEqual(settings.DEFAULT_CONTENT_TYPE, 'text/xml') 
开发者ID:nesdis,项目名称:djongo,代码行数:7,代码来源:test_default_content_type.py


注:本文中的django.conf.settings.DEFAULT_CONTENT_TYPE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。