title: Django Debug "IndexError: list index out of range"
body: <p>I am working on a django project for a while and all over sudden the django's debug stopped working displaying the following exception instead of showing the traceback of the bug in my code.</p>
  
  <p>This exception seems to be a problem in the debugger itself and has been discussed in several places indicating that it could be a problem with line breaks in Mac (<a href="https://groups.google.com/group/django-users/browse_thread/thread/711bb08fa81c3d67/bb755bde3335fc32?lnk=gst&amp;q=IndexError%3a+list+index+out+of+range&amp;hl=en" rel="nofollow">here</a>) and a line mismatch in the stack and the code on the disk (<a href="http://permalink.gmane.org/gmane.comp.python.django.user/109299" rel="nofollow">here</a>).</p>
  
  <p>Interestingly though, this exception only occurs when there is an exception that is NOT due to a syntax error. If I randomly add incorrect syntax, django show the normal debug interface indicating "invalid syntax (views.py, line xyz)".</p>
  
  <p>I am using Django 1.3, Python 2.7, Ubuntu 11.04. The project is a couple of thousand lines strong, so it would be hard to copy and paste it in here.</p>
  
  <p>Did anybody stumble across this as well and knows what other factors can cause this and how to fix it?</p>
  
  <pre><code>Traceback (most recent call last):
  
   File "/usr/local/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 283, in run
    self.result = application(self.environ, self.start_response)
  
   File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 68, in __call__
    return self.application(environ, start_response)
  
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 273, in __call__
    response = self.get_response(request)
  
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 169, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  
   File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 203, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  
   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 59, in technical_500_response
    html = reporter.get_traceback_html()
  
   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 114, in get_traceback_html
    frames = self.get_traceback_frames()
  
   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 242, in get_traceback_frames
    pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(filename, lineno, 7, loader, module_name)
  
   File "/usr/local/lib/python2.7/dist-packages/django/views/debug.py", line 223, in _get_lines_from_file
    context_line = source[lineno].strip('\n')
  
   IndexError: list index out of range
  </code></pre>