Django Debug“IndexError:列表索引超出范围”

时间:2011-12-22 08:56:50

标签: python django debugging exception

我正在研究一个django项目一段时间,突然间django的调试停止工作,显示以下异常,而不是在我的代码中显示bug的回溯。

这个异常似乎是调试器本身的一个问题,并且已在几个地方进行了讨论,表明它可能是Mac(here)中的换行符和堆栈中的行不匹配问题在磁盘上(here)。

有趣的是,只有当异常不是由于语法错误时才会发生此异常。如果我随机添加不正确的语法,django会显示正常的调试界面,指示“语法无效(views.py,line xyz)”。

我使用的是Django 1.3,Python 2.7,Ubuntu 11.04。该项目强大了几千行,因此很难将其复制并粘贴到此处。

是否有人偶然发现了这一点并知道其他因素会导致这种情况以及如何解决这个问题?

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

2 个答案:

答案 0 :(得分:0)

我无法找到问题的解决方案,但我找到了一种方法,至少可以通过使用不同的调试器获得更多信息性回溯。

转到此处:https://github.com/dcramer/django-devserver

- 在devserver上进行pip安装

-apip install of werkzeug

-add dev-server to settings in your settings.py

-start django with ./manage.py runserver --werkzeug

答案 1 :(得分:0)

我遇到了这个问题,因为即使在我的应用程序中touch wsgi.py文件后,我也没有重启/重新加载HTTP服务器。

我在守护进程模式下运行Django / WSGI。

我通过重新加载Web服务器来修复它:

的Apache:

“systemd”Linux发行版:

# systemctl reload httpd.service

大多数发行版:

# apachectl -k graceful

我知道这可能不是你遇到的特殊问题,但它可能对其他人有帮助。