本文整理匯總了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
示例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
示例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
示例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
示例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')
示例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)
示例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
示例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']
示例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
示例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')