Fixed #11834 -- Improved technical 500 stacktrace display.

Thanks to buriy and Aleksandra for the implementation!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16343 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Idan Gazit 2011-06-09 12:45:11 +00:00
parent 38878b599a
commit 716601109a
2 changed files with 23 additions and 7 deletions

View File

@ -382,11 +382,12 @@ class ExceptionReporter(object):
function = tb.tb_frame.f_code.co_name function = tb.tb_frame.f_code.co_name
lineno = tb.tb_lineno - 1 lineno = tb.tb_lineno - 1
loader = tb.tb_frame.f_globals.get('__loader__') loader = tb.tb_frame.f_globals.get('__loader__')
module_name = tb.tb_frame.f_globals.get('__name__') module_name = tb.tb_frame.f_globals.get('__name__') or ''
pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name) pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
if pre_context_lineno is not None: if pre_context_lineno is not None:
frames.append({ frames.append({
'tb': tb, 'tb': tb,
'type': module_name.startswith('django.') and 'django' or 'user',
'filename': filename, 'filename': filename,
'function': function, 'function': function,
'lineno': lineno + 1, 'lineno': lineno + 1,
@ -483,16 +484,20 @@ TECHNICAL_500_TEMPLATE = """
table td.code pre { overflow:hidden; } table td.code pre { overflow:hidden; }
table.source th { color:#666; } table.source th { color:#666; }
table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; } table.source td { font-family:monospace; white-space:pre; border-bottom:1px solid #eee; }
ul.traceback { list-style-type:none; } ul.traceback { list-style-type:none; color: #222; }
ul.traceback li.frame { padding-bottom:1em; } ul.traceback li.frame { padding-bottom:1em; color:#666; }
ul.traceback li.user { background-color:#e0e0e0; color:#000 }
div.context { padding:10px 0; overflow:hidden; } div.context { padding:10px 0; overflow:hidden; }
div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; } div.context ol { padding-left:30px; margin:0 10px; list-style-position: inside; }
div.context ol li { font-family:monospace; white-space:pre; color:#666; cursor:pointer; } div.context ol li { font-family:monospace; white-space:pre; color:#777; cursor:pointer; }
div.context ol li pre { display:inline; } div.context ol li pre { display:inline; }
div.context ol.context-line li { color:black; background-color:#ccc; } div.context ol.context-line li { color:#505050; background-color:#dfdfdf; }
div.context ol.context-line li span { position:absolute; right:32px; } div.context ol.context-line li span { position:absolute; right:32px; }
.user div.context ol.context-line li { background-color:#bbb; color:#000; }
.user div.context ol li { color:#666; }
div.commands { margin-left: 40px; } div.commands { margin-left: 40px; }
div.commands a { color:black; text-decoration:none; } div.commands a { color:#555; text-decoration:none; }
.user div.commands a { color: black; }
#summary { background: #ffc; } #summary { background: #ffc; }
#summary h2 { font-weight: normal; color: #666; } #summary h2 { font-weight: normal; color: #666; }
#explanation { background:#eee; } #explanation { background:#eee; }
@ -671,7 +676,7 @@ TECHNICAL_500_TEMPLATE = """
<div id="browserTraceback"> <div id="browserTraceback">
<ul class="traceback"> <ul class="traceback">
{% for frame in frames %} {% for frame in frames %}
<li class="frame"> <li class="frame {{ frame.type }}">
<code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code> <code>{{ frame.filename|escape }}</code> in <code>{{ frame.function|escape }}</code>
{% if frame.context_line %} {% if frame.context_line %}

View File

@ -136,6 +136,17 @@ You may override or customize the default filtering by writing a
:ref:`Filtering error reports<filtering-error-reports>`. :ref:`Filtering error reports<filtering-error-reports>`.
Minor features
~~~~~~~~~~~~~~
Django 1.4 also includes several smaller improvements worth noting:
* A more usable stacktrace in the technical 500 page: frames in the stack
trace which reference Django's code are dimmed out, while frames in user
code are slightly emphasized. This change makes it easier to scan a stacktrace
for issues in user code.
.. _backwards-incompatible-changes-1.4: .. _backwards-incompatible-changes-1.4:
Backwards incompatible changes in 1.4 Backwards incompatible changes in 1.4