1

我似乎无法弄清楚为什么我突然开始列出服务器错误。有任何想法吗?

完整的追溯:

Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 179, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 221, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 66, in technical_500_response
    html = reporter.get_traceback_html()
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 286, in get_traceback_html
    c = Context(self.get_traceback_data())
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 244, in get_traceback_data
    frames = self.get_traceback_frames()
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 390, 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 "C:\Python27\lib\site-packages\django\views\debug.py", line 371, in _get_lines_from_file
    context_line = source[lineno].strip('\n')
IndexError: list index out of range
[01/Nov/2012 10:46:55] "GET /home HTTP/1.1" 500 59
Traceback (most recent call last):
  File "C:\Python27\lib\wsgiref\handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Python27\lib\site-packages\django\contrib\staticfiles\handlers.py", line 67, in __call__
    return self.application(environ, start_response)
  File "C:\Python27\lib\site-packages\django\core\handlers\wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 179, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "C:\Python27\lib\site-packages\django\core\handlers\base.py", line 221, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 66, in technical_500_response
    html = reporter.get_traceback_html()
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 286, in get_traceback_html
    c = Context(self.get_traceback_data())
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 244, in get_traceback_data
    frames = self.get_traceback_frames()
  File "C:\Python27\lib\site-packages\django\views\debug.py", line 390, 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 "C:\Python27\lib\site-packages\django\views\debug.py", line 371, in _get_lines_from_file
    context_line = source[lineno].strip('\n')
IndexError: list index out of range
4

2 回答 2

3

我不知道您使用的是任何类型的网络服务器,还是只是开发服务器。在任何情况下,关闭您正在使用的任何服务器,并清理项目中的所有 .pyc 文件。重新启动网络服务器,您应该一切顺利。

最常见的是编译文件和源文件不匹配。至于为什么会发生这种情况,没有任何线索,但它过去曾发生在我身上:做上述为我解决了它。

于 2012-11-01T15:07:36.303 回答
1

所以我终于弄明白了……我设置了 debug = False,只是为了看看会发生什么,因为回溯包含 debug.py。无论如何,我仍然是一个初学者,甚至不知道这是否真的有意义,但是在我在我的设置中更改 debug = False 之后,我得到了一个新的回溯,它告诉我我的一个 CHOICES 在我的一个表格不匹配。我完全不明白为什么这会使开发服务器崩溃,但我修复了它,现在它可以工作了。因此,要澄清问题所在:

#forms.py

PAYMENT_PLAN = {
    ('A', 'A'),
    ('B', 'B'),
    ('C', 'C'),
}

class SurveyForm(ModelForm):
    class Meta:
        model = Survey
        widgets = {
            'pay_plan': Select(choices=PAY_PLAN),
            ...
        }

因此,带有 debug=False 的新回溯声明:

NameError: name 'PAY_PLAN' is not defined

所以无论如何,我解决了这个问题,现在它又可以工作了。因此,如果有人遇到同样的问题,请尝试将 debug=False 设置为看看会发生什么,也许它会帮助您解决问题。

于 2012-11-01T20:03:19.060 回答