Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django调试“索引器:列表索引超出范围”_Python_Django_Debugging_Exception - Fatal编程技术网

Python Django调试“索引器:列表索引超出范围”

Python Django调试“索引器:列表索引超出范围”,python,django,debugging,exception,Python,Django,Debugging,Exception,我在django项目上工作了一段时间,django的调试突然停止工作,显示以下异常,而不是在代码中显示错误的回溯 此异常似乎是调试器本身的一个问题,并且已在多个地方讨论过,这表明它可能是Mac中的换行以及堆栈中的行与磁盘上的代码不匹配的问题 然而,有趣的是,只有当存在非语法错误引起的异常时,才会发生此异常。如果我随机添加不正确的语法,django将显示正常的调试界面,指示无效的语法views.py,第xyz行 我使用的是Django 1.3、Python 2.7、Ubuntu 11.04。这个项

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

此异常似乎是调试器本身的一个问题,并且已在多个地方讨论过,这表明它可能是Mac中的换行以及堆栈中的行与磁盘上的代码不匹配的问题

然而,有趣的是,只有当存在非语法错误引起的异常时,才会发生此异常。如果我随机添加不正确的语法,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

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

到这里:

-在devserver上执行pip安装

-werkzeug的pip安装

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

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