Skip to content

Commit 8045dff

Browse files
committed
Refs #27829 -- Removed settings.DEFAULT_CONTENT_TYPE per deprecation timeline.
1 parent 573ec71 commit 8045dff

File tree

11 files changed

+16
-114
lines changed

11 files changed

+16
-114
lines changed

django/conf/__init__.py

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
import django
1717
from django.conf import global_settings
1818
from django.core.exceptions import ImproperlyConfigured
19-
from django.utils.deprecation import (
20-
RemovedInDjango30Warning, RemovedInDjango31Warning,
21-
)
19+
from django.utils.deprecation import RemovedInDjango31Warning
2220
from django.utils.functional import LazyObject, empty
2321

2422
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
2523

26-
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG = 'The DEFAULT_CONTENT_TYPE setting is deprecated.'
2724
FILE_CHARSET_DEPRECATED_MSG = (
2825
'The FILE_CHARSET setting is deprecated. Starting with Django 3.1, all '
2926
'files read from disk must be UTF-8 encoded.'
@@ -115,20 +112,6 @@ def configured(self):
115112
"""Return True if the settings have already been configured."""
116113
return self._wrapped is not empty
117114

118-
@property
119-
def DEFAULT_CONTENT_TYPE(self):
120-
stack = traceback.extract_stack()
121-
# Show a warning if the setting is used outside of Django.
122-
# Stack index: -1 this line, -2 the caller.
123-
filename, _line_number, _function_name, _text = stack[-2]
124-
if not filename.startswith(os.path.dirname(django.__file__)):
125-
warnings.warn(
126-
DEFAULT_CONTENT_TYPE_DEPRECATED_MSG,
127-
RemovedInDjango30Warning,
128-
stacklevel=2,
129-
)
130-
return self.__getattr__('DEFAULT_CONTENT_TYPE')
131-
132115
@property
133116
def FILE_CHARSET(self):
134117
stack = traceback.extract_stack()
@@ -175,8 +158,6 @@ def __init__(self, settings_module):
175158
if not self.SECRET_KEY:
176159
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.")
177160

178-
if self.is_overridden('DEFAULT_CONTENT_TYPE'):
179-
warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
180161
if self.is_overridden('FILE_CHARSET'):
181162
warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
182163

@@ -223,9 +204,7 @@ def __getattr__(self, name):
223204

224205
def __setattr__(self, name, value):
225206
self._deleted.discard(name)
226-
if name == 'DEFAULT_CONTENT_TYPE':
227-
warnings.warn(DEFAULT_CONTENT_TYPE_DEPRECATED_MSG, RemovedInDjango30Warning)
228-
elif name == 'FILE_CHARSET':
207+
if name == 'FILE_CHARSET':
229208
warnings.warn(FILE_CHARSET_DEPRECATED_MSG, RemovedInDjango31Warning)
230209
super().__setattr__(name, value)
231210

django/conf/global_settings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,8 @@ def gettext_noop(s):
164164
# notifications and other various emails.
165165
MANAGERS = ADMINS
166166

167-
# Default content type and charset to use for all HttpResponse objects, if a
168-
# MIME type isn't manually specified. These are used to construct the
169-
# Content-Type header.
170-
DEFAULT_CONTENT_TYPE = 'text/html'
167+
# Default charset to use for all HttpResponse objects, if a MIME type isn't
168+
# manually specified. It's used to construct the Content-Type header.
171169
DEFAULT_CHARSET = 'utf-8'
172170

173171
# Encoding of files read from disk (template and initial SQL files).

django/http/response.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ def __init__(self, content_type=None, status=None, reason=None, charset=None):
5757
self._reason_phrase = reason
5858
self._charset = charset
5959
if content_type is None:
60-
content_type = '%s; charset=%s' % (settings.DEFAULT_CONTENT_TYPE,
61-
self.charset)
60+
content_type = 'text/html; charset=%s' % self.charset
6261
self['Content-Type'] = content_type
6362

6463
@property
@@ -427,7 +426,7 @@ def set_headers(self, filelike):
427426
elif hasattr(filelike, 'getbuffer'):
428427
self['Content-Length'] = filelike.getbuffer().nbytes
429428

430-
if self.get('Content-Type', '').startswith(settings.DEFAULT_CONTENT_TYPE):
429+
if self.get('Content-Type', '').startswith('text/html'):
431430
if filename:
432431
content_type, encoding = mimetypes.guess_type(filename)
433432
# Encoding isn't set to prevent browsers from automatically

django/views/defaults.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def page_not_found(request, exception, template_name=ERROR_404_TEMPLATE_NAME):
4747
try:
4848
template = loader.get_template(template_name)
4949
body = template.render(context, request)
50-
content_type = None # Django will use DEFAULT_CONTENT_TYPE
50+
content_type = None # Django will use 'text/html'.
5151
except TemplateDoesNotExist:
5252
if template_name != ERROR_404_TEMPLATE_NAME:
5353
# Reraise if it's a missing custom template.

docs/ref/class-based-views/mixins-simple.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Simple mixins
8383

8484
The content type to use for the response. ``content_type`` is passed
8585
as a keyword argument to ``response_class``. Default is ``None`` --
86-
meaning that Django uses :setting:`DEFAULT_CONTENT_TYPE`.
86+
meaning that Django uses ``'text/html'``.
8787

8888
**Methods**
8989

docs/ref/request-response.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ Methods
748748

749749
``content_type`` is the MIME type optionally completed by a character set
750750
encoding and is used to fill the HTTP ``Content-Type`` header. If not
751-
specified, it is formed by the :setting:`DEFAULT_CONTENT_TYPE` and
751+
specified, it is formed by ``'text/html'`` and the
752752
:setting:`DEFAULT_CHARSET` settings, by default: "`text/html; charset=utf-8`".
753753

754754
``status`` is the :rfc:`HTTP status code <7231#section-6>` for the response.

docs/ref/settings.txt

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,24 +1195,7 @@ See also :setting:`NUMBER_GROUPING`, :setting:`THOUSAND_SEPARATOR` and
11951195
Default: ``'utf-8'``
11961196

11971197
Default charset to use for all ``HttpResponse`` objects, if a MIME type isn't
1198-
manually specified. Used with :setting:`DEFAULT_CONTENT_TYPE` to construct the
1199-
``Content-Type`` header.
1200-
1201-
.. setting:: DEFAULT_CONTENT_TYPE
1202-
1203-
``DEFAULT_CONTENT_TYPE``
1204-
------------------------
1205-
1206-
Default: ``'text/html'``
1207-
1208-
Default content type to use for all ``HttpResponse`` objects, if a MIME type
1209-
isn't manually specified. Used with :setting:`DEFAULT_CHARSET` to construct
1210-
the ``Content-Type`` header.
1211-
1212-
.. deprecated:: 2.0
1213-
1214-
This setting is deprecated because it doesn't interact well with
1215-
third-party apps and is obsolete since HTML5 has mostly superseded XHTML.
1198+
manually specified. Used when constructing the ``Content-Type`` header.
12161199

12171200
.. setting:: DEFAULT_EXCEPTION_REPORTER_FILTER
12181201

@@ -3436,7 +3419,6 @@ HTTP
34363419
* :setting:`DATA_UPLOAD_MAX_MEMORY_SIZE`
34373420
* :setting:`DATA_UPLOAD_MAX_NUMBER_FIELDS`
34383421
* :setting:`DEFAULT_CHARSET`
3439-
* :setting:`DEFAULT_CONTENT_TYPE`
34403422
* :setting:`DISALLOWED_USER_AGENTS`
34413423
* :setting:`FORCE_SCRIPT_NAME`
34423424
* :setting:`INTERNAL_IPS`

docs/ref/template-response.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Methods
7676
The value included in the HTTP ``Content-Type`` header, including the
7777
MIME type specification and the character set encoding. If
7878
``content_type`` is specified, then its value is used. Otherwise,
79-
:setting:`DEFAULT_CONTENT_TYPE` is used.
79+
``'text/html'`` is used.
8080

8181
``status``
8282
The HTTP status code for the response.
@@ -171,7 +171,7 @@ Methods
171171
The value included in the HTTP ``Content-Type`` header, including the
172172
MIME type specification and the character set encoding. If
173173
``content_type`` is specified, then its value is used. Otherwise,
174-
:setting:`DEFAULT_CONTENT_TYPE` is used.
174+
``'text/html'`` is used.
175175

176176
``status``
177177
The HTTP status code for the response.

docs/releases/3.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,8 @@ to remove usage of these features.
240240

241241
* ``django.shortcuts.render_to_response()`` is removed.
242242

243+
* The ``DEFAULT_CONTENT_TYPE`` setting is removed.
244+
243245
See :ref:`deprecated-features-2.1` for details on these changes, including how
244246
to remove usage of these features.
245247

docs/topics/http/shortcuts.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ Optional arguments
4646
view will call it just before rendering the template.
4747

4848
``content_type``
49-
The MIME type to use for the resulting document. Defaults to the value of
50-
the :setting:`DEFAULT_CONTENT_TYPE` setting.
49+
The MIME type to use for the resulting document. Defaults to
50+
``'text/html'``.
5151

5252
``status``
5353
The status code for the response. Defaults to ``200``.

0 commit comments

Comments
 (0)