【问题标题】:Django Debug "IndexError: list index out of range"Django 调试“IndexError:列表索引超出范围”
【发布时间】:2012-01-25 22:49:42
【问题描述】:

我在 django 项目上工作了一段时间,突然 django 的调试停止工作,显示以下异常,而不是在我的代码中显示错误的回溯。

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

有趣的是,这个异常只发生在不是由于语法错误引起的异常时。如果我随机添加不正确的语法,django 会显示正常的调试界面,指示“无效语法(views.py,行 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

【问题讨论】:

    标签: python django debugging exception


    【解决方案1】:

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

    去这里:https://github.com/dcramer/django-devserver

    -在开发服务器上进行 pip 安装

    -werkzeug 的 pip 安装

    -在 settings.py 中将 dev-server 添加到您的应用中

    -使用 ./manage.py runserver --werkzeug 启动 django

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-31
      • 2015-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多