Django

Code

Changeset 5862

Show
Ignore:
Timestamp:
08/11/07 22:23:53 (1 year ago)
Author:
adrian
Message:

Fixed #5046 -- Added 'Unicode error hint' section to debug page in the case of a UnicodeError?. Thanks, Thomas Guttler

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/views/debug.py

    r5609 r5862  
    124124            'lineno': '?', 
    125125        }] 
     126 
     127    unicode_hint = '' 
     128    if issubclass(exc_type, UnicodeError): 
     129        start = getattr(exc_value, 'start', None) 
     130        end = getattr(exc_value, 'end', None) 
     131        if start is not None and end is not None: 
     132            unicode_str = exc_value.args[1] 
     133            unicode_hint = smart_unicode(unicode_str[max(start-5, 0):min(end+5, len(unicode_str))], 'ascii', errors='replace') 
     134 
    126135    t = Template(TECHNICAL_500_TEMPLATE, name='Technical 500 template') 
    127136    c = Context({ 
    128137        'exception_type': exc_type.__name__, 
    129138        'exception_value': smart_unicode(exc_value, errors='replace'), 
     139        'unicode_hint': unicode_hint, 
    130140        'frames': frames, 
    131141        'lastframe': frames[-1], 
     
    259269    #template, #template-not-exist { background:#f6f6f6; } 
    260270    #template-not-exist ul { margin: 0 0 0 20px; } 
     271    #unicode-hint { background:#eee; } 
    261272    #traceback { background:#eee; } 
    262273    #requestinfo { background:#f6f6f6; padding-left:120px; } 
     
    359370  </table> 
    360371</div> 
     372{% if unicode_hint %} 
     373<div id="unicode-hint"> 
     374    <h2>Unicode error hint</h2> 
     375    <p>The string that could not be encoded/decoded was: <strong>{{ unicode_hint|escape }}</strong></p> 
     376</div> 
     377{% endif %} 
    361378{% if template_does_not_exist %} 
    362379<div id="template-not-exist">