我怎样才能知道我在Django遇到了什么样的错误?

我怎样才能知道我在Django遇到了什么样的错误?,django,debugging,Django,Debugging,当我浏览网页时(http://68.123.151.234/static/quickstart.html)在Django生成的服务器上提供的Django应用程序中,页面读取 A server error occurred. Please contact the administrator. 我收到了回溯 Traceback (most recent call last): File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in

当我浏览网页时(http://68.123.151.234/static/quickstart.html)在Django生成的服务器上提供的Django应用程序中,页面读取

A server error occurred.  Please contact the administrator.
我收到了回溯

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, 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 228, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
[17/May/2012 11:31:45] "GET /static/quickstart.html HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, 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 228, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
这个回溯只告诉我需要一个500模板,而不是实际的服务器错误。如何找出服务器错误是什么


我查看了Django文档(),它指导我创建一个500错误模板作为一个潜在的解决方案。但是,它没有说明如何在这样的模板中显示错误。

我认为当
DEBUG
设置为
False
时,您需要一个500.html模板

创建一个并将其放在模板目录中


每当出现500错误时,它就会显示给用户。

如果您正在测试站点,请设置
DEBUG=True
,然后Django将显示回溯

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, 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 228, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
[17/May/2012 11:31:45] "GET /static/quickstart.html HTTP/1.1" 500 59
Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
    response = self.get_response(request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, 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 228, in handle_uncaught_exception
    return callback(request, **param_dict)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py", line 91, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/views/defaults.py", line 32, in server_error
    t = loader.get_template(template_name) # You need to create a 500.html template.
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 145, in get_template
    template, origin = find_template(template_name)
  File "/usr/local/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
    raise TemplateDoesNotExist(name)
TemplateDoesNotExist: 500.html
一旦站点处于活动状态,您可能不希望在错误页面上显示回溯,因为它可能包含敏感信息

如果您添加500个模板。Django随后将向ADMINS设置中列出的用户发送一封包含回溯的电子邮件

有关更多信息,请参阅上的文档

TemplateDoesNotExist: 500.html

我认为您应该在模板目录中创建500.html。

一个方便实用的基本500.html,正如阿拉斯代尔所说,可能会揭示一些敏感信息

但是,如果以负责任的方式在web上进行调试是目标,那么站点模板目录的基本nondefault500.html模板如下所示

<html><head><body>
<!-- starting with sys.exc_info but hey, it's python -->
Type: {{ type }} <br />
Value: {{ value }} <br />
Traceback: {{ traceback }} <br />
</body></head></html>
需要进行一次调整

handler500 = 'mysite.views.this_server_error'

您的
DEBUG
是否设置为
True
?Django不会在
DEBUG
设置为
False
时显示回溯。