mirror of https://github.com/django/django.git
Refs #30324 -- Forced utf-8 encoding when loading templates for the technical 404 debug and congrats page.
This commit is contained in:
parent
efb257a017
commit
6b4e57d79f
|
@ -497,7 +497,7 @@ def technical_404_response(request, exception):
|
||||||
module = obj.__module__
|
module = obj.__module__
|
||||||
caller = '%s.%s' % (module, caller)
|
caller = '%s.%s' % (module, caller)
|
||||||
|
|
||||||
with Path(CURRENT_DIR, 'templates', 'technical_404.html').open() as fh:
|
with Path(CURRENT_DIR, 'templates', 'technical_404.html').open(encoding='utf-8') as fh:
|
||||||
t = DEBUG_ENGINE.from_string(fh.read())
|
t = DEBUG_ENGINE.from_string(fh.read())
|
||||||
c = Context({
|
c = Context({
|
||||||
'urlconf': urlconf,
|
'urlconf': urlconf,
|
||||||
|
@ -514,7 +514,7 @@ def technical_404_response(request, exception):
|
||||||
|
|
||||||
def default_urlconf(request):
|
def default_urlconf(request):
|
||||||
"""Create an empty URLconf 404 error response."""
|
"""Create an empty URLconf 404 error response."""
|
||||||
with Path(CURRENT_DIR, 'templates', 'default_urlconf.html').open() as fh:
|
with Path(CURRENT_DIR, 'templates', 'default_urlconf.html').open(encoding='utf-8') as fh:
|
||||||
t = DEBUG_ENGINE.from_string(fh.read())
|
t = DEBUG_ENGINE.from_string(fh.read())
|
||||||
c = Context({
|
c = Context({
|
||||||
'version': get_docs_version(),
|
'version': get_docs_version(),
|
||||||
|
|
|
@ -224,6 +224,19 @@ class DebugViewTests(SimpleTestCase):
|
||||||
status_code=404
|
status_code=404
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_template_encoding(self):
|
||||||
|
"""
|
||||||
|
The templates are loaded directly, not via a template loader, and
|
||||||
|
should be opened as utf-8 charset as is the default specified on
|
||||||
|
template engines.
|
||||||
|
"""
|
||||||
|
with mock.patch.object(DebugPath, 'open') as m:
|
||||||
|
default_urlconf(None)
|
||||||
|
m.assert_called_once_with(encoding='utf-8')
|
||||||
|
m.reset_mock()
|
||||||
|
technical_404_response(mock.MagicMock(), mock.Mock())
|
||||||
|
m.assert_called_once_with(encoding='utf-8')
|
||||||
|
|
||||||
|
|
||||||
class DebugViewQueriesAllowedTests(SimpleTestCase):
|
class DebugViewQueriesAllowedTests(SimpleTestCase):
|
||||||
# May need a query to initialize MySQL connection
|
# May need a query to initialize MySQL connection
|
||||||
|
|
Loading…
Reference in New Issue