如何从Django错误消息中过滤信息?

时间:2016-07-19 15:21:00

标签: python django

当我的Django站点(通常是500)发生错误时,我从服务器收到一条很长的错误消息(如本例所示):

TypeError at /c/ajax/import_onboard/
argument of type 'NoneType' is not iterable

Request Method: POST
Request URL: http://127.0.0.1:8000/c/ajax/import_onboard/
Django Version: 1.8.11
Python Executable: C:\Python27\python.exe
Python Version: 2.7.10
Python Path: ['C:\\Repos\\my-app', 'C:\\Python27\\lib\\site-packages\\setuptools-18.0.1-py2
.7.egg', 'C:\\windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27
\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages']
Server time: Tue, 19 Jul 2016 14:59:19 +0000
Installed Applications:
('myapp_1',
 'myapp_2',
 'myapp_3',
 'django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'debug_toolbar',
 'debug_panel')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'debug_panel.middleware.DebugPanelMiddleware')

Traceback:
File "C:\Python27\lib\site-packages\django\core\handlers\base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Python27\lib\site-packages\django\views\decorators\csrf.py" in wrapped_view
  58.         return view_func(*args, **kwargs)

... snip ...

我讨厌这么长的回应。有没有办法可以从打印的内容中删除 Python版 Python Path 已安装的应用程序等项目?我很想拥有追溯信息,所以我不必向下滚动以查看问题所在。

1 个答案:

答案 0 :(得分:1)

您可以使用自己的模板重新定义错误视图:

handler500 = 'mysite.views.my_custom_error_view'

https://docs.djangoproject.com/en/1.9/topics/http/views/#customizing-error-views

别无他法。