summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2018-12-27 19:49:03 -0500
committerTim Graham <timograham@gmail.com>2019-01-17 10:50:25 -0500
commit8045dff98c2533e7e99ce82f80292fc6f3bb7e1f (patch)
treecea0480096b2b285b4664db28b30e3b36db6092e /django
parent573ec714e5f52eccde01bbac3836d0edafcb2c20 (diff)
Refs #27829 -- Removed settings.DEFAULT_CONTENT_TYPE per deprecation timeline.
Diffstat (limited to 'django')
-rw-r--r--django/conf/__init__.py25
-rw-r--r--django/conf/global_settings.py6
-rw-r--r--django/http/response.py5
-rw-r--r--django/views/defaults.py2
4 files changed, 7 insertions, 31 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index cf91ce83d4..608ad256dc 100644
--- a/django/conf/__init__.py
+++ b/django/conf/__init__.py
@@ -16,14 +16,11 @@ from pathlib import Path
import django
from django.conf import global_settings
from django.core.exceptions import ImproperlyConfigured
-from django.utils.deprecation import (
- RemovedInDjango30Warning, RemovedInDjango31Warning,
-)
+from django.utils.deprecation import RemovedInDjango31Warning
from django.utils.functional import LazyObject, empty
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
-DEFAULT_CONTENT_TYPE_DEPRECATED_MSG = 'The DEFAULT_CONTENT_TYPE setting is deprecated.'
FILE_CHARSET_DEPRECATED_MSG = (
'The FILE_CHARSET setting is deprecated. Starting with Django 3.1, all '
'files read from disk must be UTF-8 encoded.'
@@ -116,20 +113,6 @@ class LazySettings(LazyObject):
return self._wrapped is not empty
@property
- def DEFAULT_CONTENT_TYPE(self):
- stack = traceback.extract_stack()
- # Show a warning if the setting is used outside of Django.
- # Stack index: -1 this line, -2 the caller.
- filename, _line_number, _function_name, _text = stack[-2]
- if not filename.startswith(os.path.dirname(django.__file__)):
- warnings.warn(
- DEFAULT_CONTENT_TYPE_DEPRECATED_MSG,
- RemovedInDjango30Warning,
- stacklevel=2,
- )
- return self.__getattr__('DEFAULT_CONTENT_TYPE')
-
- @property
def FILE_CHARSET(self):
stack = traceback.extract_stack()
# Show a warning if the setting is used outside of Django.
@@ -175,8 +158,6 @@ class Settings:
if not self.SECRET_KEY:
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
- if self.is_overridden('DEFAULT_CONTENT_TYPE'):
- warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
if self.is_overridden('FILE_CHARSET'):
warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
@@ -223,9 +204,7 @@ class UserSettingsHolder:
def __setattr__(self, name, value):
self._deleted.discard(name)
- if name == 'DEFAULT_CONTENT_TYPE':
- warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
- elif name == 'FILE_CHARSET':
+ if name == 'FILE_CHARSET':
warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
super().__setattr__(name, value)
diff --git a/django/conf/global_settings.py b/django/conf/global_settings.py
index 03aa87bf21..acee9887d2 100644
--- a/django/conf/global_settings.py
+++ b/django/conf/global_settings.py
@@ -164,10 +164,8 @@ USE_L10N = False
# notifications and other various emails.
MANAGERS = ADMINS
-# Default content type and charset to use for all HttpResponse objects, if a
-# MIME type isn't manually specified. These are used to construct the
-# Content-Type header.
-DEFAULT_CONTENT_TYPE = 'text/html'
+# Default charset to use for all HttpResponse objects, if a MIME type isn't
+# manually specified. It's used to construct the Content-Type header.
DEFAULT_CHARSET = 'utf-8'
# Encoding of files read from disk (template and initial SQL files).
diff --git a/django/http/response.py b/django/http/response.py
index f7d248e933..5a640a51cf 100644
--- a/django/http/response.py
+++ b/django/http/response.py
@@ -57,8 +57,7 @@ class HttpResponseBase:
self._reason_phrase = reason
self._charset = charset
if content_type is None:
- content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
- self.charset)
+ content_type = 'text/html; charset=%s' % self.charset
self['Content-Type'] = content_type
@property
@@ -427,7 +426,7 @@ class FileResponse(StreamingHttpResponse):
elif hasattr(filelike, 'getbuffer'):
self['Content-Length'] = filelike.getbuffer().nbytes
- if self.get('Content-Type', '').startswith(settings.DEFAULT_CONTENT_TYPE):
+ if self.get('Content-Type', '').startswith('text/html'):
if filename:
content_type, encoding = mimetypes.guess_type(filename)
# Encoding isn't set to prevent browsers from automatically
diff --git a/django/views/defaults.py b/django/views/defaults.py
index 8bf60c9d74..1176bdeeeb 100644
--- a/django/views/defaults.py
+++ b/django/views/defaults.py
@@ -47,7 +47,7 @@ def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
try:
template = loader.get_template(template_name)
body = template.render(context, request)
- content_type = None # Django will use DEFAULT_CONTENT_TYPE
+ content_type = None # Django will use 'text/html'.
except TemplateDoesNotExist:
if template_name != ERROR_404_TEMPLATE_NAME:
# Reraise if it's a missing custom template.