summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-04-25 11:01:21 -0400
committerTim Graham <timograham@gmail.com>2017-04-25 11:01:34 -0400
commit4a89000ccf0483c67f66709cca90fc50ad82aacc (patch)
tree723f2a06d921c2a9efc020996cb567e517b13024
parent7eecf496eecdf9ce1227e0ea517d32880e3300d9 (diff)
[1.11.x] Fixed #28122 -- Fixed crash when overriding views.static.directory_index()'s template.
Backport of 56970c5b61f8f1612944dc54b72ef210d433066f from master
-rw-r--r--django/views/static.py5
-rw-r--r--docs/releases/1.11.1.txt3
-rw-r--r--tests/view_tests/tests/test_static.py14
3 files changed, 21 insertions, 1 deletions
diff --git a/django/views/static.py b/django/views/static.py
index 4f62630079..413b0bd13d 100644
--- a/django/views/static.py
+++ b/django/views/static.py
@@ -94,13 +94,16 @@ def directory_index(path, fullpath):
])
except TemplateDoesNotExist:
t = Engine(libraries={'i18n': 'django.templatetags.i18n'}).from_string(DEFAULT_DIRECTORY_INDEX_TEMPLATE)
+ c = Context()
+ else:
+ c = {}
files = []
for f in os.listdir(fullpath):
if not f.startswith('.'):
if os.path.isdir(os.path.join(fullpath, f)):
f += '/'
files.append(f)
- c = Context({
+ c.update({
'directory': path + '/',
'file_list': files,
})
diff --git a/docs/releases/1.11.1.txt b/docs/releases/1.11.1.txt
index 78715791e7..a76806c2fb 100644
--- a/docs/releases/1.11.1.txt
+++ b/docs/releases/1.11.1.txt
@@ -55,3 +55,6 @@ Bugfixes
* Fixed a regression causing incorrect queries for ``__in`` subquery lookups
when models use ``ForeignKey.to_field`` (:ticket:`28101`).
+
+* Fixed crash when overriding the template of
+ ``django.views.static.directory_index()`` (:ticket:`28122`).
diff --git a/tests/view_tests/tests/test_static.py b/tests/view_tests/tests/test_static.py
index 1f5d6e5943..fa01e98425 100644
--- a/tests/view_tests/tests/test_static.py
+++ b/tests/view_tests/tests/test_static.py
@@ -112,6 +112,20 @@ class StaticTests(SimpleTestCase):
response = self.client.get('/%s/' % self.prefix)
self.assertContains(response, 'Index of ./')
+ @override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'OPTIONS': {
+ 'loaders': [
+ ('django.template.loaders.locmem.Loader', {
+ 'static/directory_index.html': 'Test index',
+ }),
+ ],
+ },
+ }])
+ def test_index_custom_template(self):
+ response = self.client.get('/%s/' % self.prefix)
+ self.assertEqual(response.content, b'Test index')
+
class StaticHelperTest(StaticTests):
"""