#21058 closed Bug (fixed)
Template Error during render results in 500 error
Reported by: | jambonrose | Owned by: | ianawilson |
---|---|---|---|
Component: | Template system | Version: | 1.5 |
Severity: | Normal | Keywords: | template, TemplateDoesNotExist, render |
Cc: | ianawilson | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Consider:
from django.shortcuts import render def testview(request): return render(request, [], {})
Accessing this view will raise a 500 error:
A server error occurred. Please contact the administrator.
The traceback is as follows:
Internal Server Error: /path_to_view/ Traceback (most recent call last): File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response response = callback(request, *callback_args, **callback_kwargs) File "/Users/jambonrose/djtest/cbgvtest/views.py", line 4, in testview return render(request, [], {}) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 53, in render return HttpResponse(loader.render_to_string(*args, **kwargs), File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/template/loader.py", line 168, in render_to_string t = select_template(template_name) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/template/loader.py", line 184, in select_template raise TemplateDoesNotExist("No template names provided") TemplateDoesNotExist: No template names provided Traceback (most recent call last): File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run self.result = application(self.environ, self.start_response) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__ return self.application(environ, start_response) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 255, in __call__ response = self.get_response(request) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/core/handlers/base.py", line 178, in get_response response = self.handle_uncaught_exception(request, resolver, sys.exc_info()) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/core/handlers/base.py", line 217, in handle_uncaught_exception return debug.technical_500_response(request, *exc_info) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/views/debug.py", line 69, in technical_500_response html = reporter.get_traceback_html() File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/views/debug.py", line 297, in get_traceback_html c = Context(self.get_traceback_data()) File "/Users/jambonrose/.virtualenvs/djtest/lib/python2.7/site-packages/django/views/debug.py", line 237, in get_traceback_data for loader in template_source_loaders: TypeError: 'NoneType' object is not iterable [06/Sep/2013 15:19:35] "GET /try/ HTTP/1.1" 500 59
Django should instead be raising a TemplateDoesNotExist
error.
The problem stems from interaction between get_traceback_data
in django/views/debug.py
and find_template
in django/template/loader.py
- the former assumes the latter has already run and provided template_source_loaders
with values in a list (an empty list is valid behavior). However, in the case above, find_template
is not run, and template_source_loaders
is set to None
.
The included patch checks for this, and replaces None
with []
resulting with the correct behavior.
Attachments (1)
Change History (6)
by , 11 years ago
Attachment: | django_get_traceback_data.patch added |
---|
comment:2 by , 11 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Patch of get_traceback_data method.