[Django] #28122: Override static/directory_index.html template will raise TypeError: context must be a dict rather than Context

7 views
Skip to first unread message

Django

unread,
Apr 25, 2017, 3:40:49 AM4/25/17
to django-...@googlegroups.com
#28122: Override static/directory_index.html template will raise TypeError: context
must be a dict rather than Context
--------------------------------------------+------------------------
Reporter: Natt Piyapramote | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
**Test step**

1. Create **templates/static/directory_index.html** with following
content

{{{
{% load i18n %}
<body>
<h1>{% blocktrans %}Index of {{ directory }}{% endblocktrans %}</h1>
<ul>
{% if directory != "/" %}
<li><a href="../">../</a></li>
{% endif %}
{% for f in file_list %}
<li><a href="{{ f|urlencode }}">{{ f }}</a></li>
{% endfor %}
</ul>
</body>
</html>
}}}

2. Config **settings.py**'s TEMPLATE_DIR to search **templates/**

{{{
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'templates' # add config
here
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
}}}

3. Use **django.views.static.serve** in **urls.py**

{{{
def browse(request):
return serve(request, request.path, '/tmp', show_indexes=True)

urlpatterns = [
url(r'^browse/', browse),
}}}

**Actual result**
{{{
TypeError at /browse/
context must be a dict rather than Context.
Request Method: GET
Request URL: http://localhost:8001/browse/
Django Version: 1.11
Exception Type: TypeError
Exception Value:
context must be a dict rather than Context.
Exception Location: /home/natt/.virtualenvs/django111/lib/python3.5
/site-packages/django/template/context.py in make_context, line 287
Python Executable: /home/natt/.virtualenvs/django111/bin/python
Python Version: 3.5.2
Python Path:
['/home/natt/tmp/demo',
'/home/natt/.virtualenvs/django111/lib/python35.zip',
'/home/natt/.virtualenvs/django111/lib/python3.5',
'/home/natt/.virtualenvs/django111/lib/python3.5/plat-x86_64-linux-gnu',
'/home/natt/.virtualenvs/django111/lib/python3.5/lib-dynload',
'/usr/lib/python3.5',
'/usr/lib/python3.5/plat-x86_64-linux-gnu',
'/home/natt/.virtualenvs/django111/lib/python3.5/site-packages']
Server time: Tue, 25 Apr 2017 07:24:00 +0000

Internal Server Error: /qml/
Traceback (most recent call last):
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/home/natt/tmp/demo/demo/urls.py", line 23, in main
return serve(request, path, '/home/natt/cnmi/his/his/qmlweb/qml',
show_indexes=True)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/views/static.py", line 43, in serve
return directory_index(path, fullpath)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/views/static.py", line 107, in directory_index
return HttpResponse(t.render(c))
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/template/backends/django.py", line 64, in render
context = make_context(context, request,
autoescape=self.backend.engine.autoescape)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/template/context.py", line 287, in make_context
raise TypeError('context must be a dict rather than %s.' %
context.__class__.__name__)
TypeError: context must be a dict rather than Context.
}}}

**Expected result**
Directory browsing render successfully
(This works correctly in Django 1.10)

--
Ticket URL: <https://code.djangoproject.com/ticket/28122>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 25, 2017, 3:41:41 AM4/25/17
to django-...@googlegroups.com
#28122: Override static/directory_index.html template will raise TypeError: context
must be a dict rather than Context
----------------------------------+--------------------------------------

Reporter: Natt Piyapramote | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Description changed by Natt Piyapramote:

Old description:

New description:

**Test step**

Internal Server Error: /browse/


Traceback (most recent call last):
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args,
**callback_kwargs)
File "/home/natt/tmp/demo/demo/urls.py", line 23, in main

return serve(request, path, '/tmp', show_indexes=True)


File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/views/static.py", line 43, in serve
return directory_index(path, fullpath)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/views/static.py", line 107, in directory_index
return HttpResponse(t.render(c))
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/template/backends/django.py", line 64, in render
context = make_context(context, request,
autoescape=self.backend.engine.autoescape)
File "/home/natt/.virtualenvs/django111/lib/python3.5/site-
packages/django/template/context.py", line 287, in make_context
raise TypeError('context must be a dict rather than %s.' %
context.__class__.__name__)
TypeError: context must be a dict rather than Context.
}}}

**Expected result**
Directory browsing render successfully
(This works correctly in Django 1.10)

--

--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:1>

Django

unread,
Apr 25, 2017, 8:34:46 AM4/25/17
to django-...@googlegroups.com
#28122: Overriding directory_index view's static/directory_index.html crashes with

TypeError: context must be a dict rather than Context
----------------------------------+--------------------------------------
Reporter: Natt Piyapramote | Owner: Tim Graham
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* status: new => assigned
* severity: Normal => Release blocker
* component: Uncategorized => Core (Other)
* owner: nobody => Tim Graham
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


Comment:

`django.views.static.directory_index()` must be updated after
6a7495051304d75865add6ff96422018984e1663.

--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:2>

Django

unread,
Apr 25, 2017, 8:47:01 AM4/25/17
to django-...@googlegroups.com
#28122: Overriding directory_index view's static/directory_index.html crashes with
TypeError: context must be a dict rather than Context
----------------------------------+--------------------------------------
Reporter: Natt Piyapramote | Owner: Tim Graham
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+--------------------------------------
Changes (by Tim Graham):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/8403 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:3>

Django

unread,
Apr 25, 2017, 10:49:00 AM4/25/17
to django-...@googlegroups.com
#28122: Overriding directory_index view's static/directory_index.html crashes with
TypeError: context must be a dict rather than Context
-------------------------------------+-------------------------------------

Reporter: Natt Piyapramote | Owner: Tim
| Graham
Type: Bug | Status: assigned
Component: Core (Other) | Version: 1.11
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:4>

Django

unread,
Apr 25, 2017, 11:01:31 AM4/25/17
to django-...@googlegroups.com
#28122: Overriding directory_index view's static/directory_index.html crashes with
TypeError: context must be a dict rather than Context
-------------------------------------+-------------------------------------
Reporter: Natt Piyapramote | Owner: Tim
| Graham
Type: Bug | Status: closed

Component: Core (Other) | Version: 1.11
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"56970c5b61f8f1612944dc54b72ef210d433066f" 56970c5b]:
{{{
#!CommitTicketReference repository=""
revision="56970c5b61f8f1612944dc54b72ef210d433066f"
Fixed #28122 -- Fixed crash when overriding
views.static.directory_index()'s template.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:5>

Django

unread,
Apr 25, 2017, 11:10:03 AM4/25/17
to django-...@googlegroups.com
#28122: Overriding directory_index view's static/directory_index.html crashes with
TypeError: context must be a dict rather than Context
-------------------------------------+-------------------------------------
Reporter: Natt Piyapramote | Owner: Tim
| Graham
Type: Bug | Status: closed
Component: Core (Other) | Version: 1.11
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"4a89000ccf0483c67f66709cca90fc50ad82aacc" 4a89000c]:
{{{
#!CommitTicketReference repository=""
revision="4a89000ccf0483c67f66709cca90fc50ad82aacc"
[1.11.x] Fixed #28122 -- Fixed crash when overriding
views.static.directory_index()'s template.

Backport of 56970c5b61f8f1612944dc54b72ef210d433066f from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/28122#comment:6>

Reply all
Reply to author
Forward
0 new messages