【发布时间】:2014-02-07 11:29:18
【问题描述】:
我需要将 django 'import error' 重定向到自定义错误页面。除了导入错误之外的所有其他错误正在重定向到自定义错误页面
已经在 DEBUG= False 浏览器中显示的错误是
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
response = self.get_response(request)
File "/usr/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/lib/python2.7/dist-packages/django/core/handlers/base.py", line 214, in handle_uncaught_exception
if resolver.urlconf_module is None:
File "/usr/lib/python2.7/dist-packages/django/core/urlresolvers.py", line 274, in _get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/usr/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/project/backup/project/hg/rel0129/hg/src/customer_/../customer_/hg/urls.py", line 4, in <module>
from lostpassword.views import recaptcha, reset
File "/project/backup/project/hg/rel0129/hg/../customer_/hg/lostpassword/views.py", line 12, in <module>
from hg.utils.common import __render, __redirect
hg/utils/common.py", line 15, in <module>
from urllibwrapper import URLClient, ClientResponse
ImportError: No module named urlwrapper
错误需要重定向到自定义错误页面
提前致谢
【问题讨论】:
-
404用于找不到页面。理想情况下,您需要500(或服务器错误)。为什么要指定404? -
我的意思是自定义错误页面或django默认错误模板。
-
导入异常是编程错误,而不是“正确的服务器,错误的 URL,抱歉!”错误。
-
如果服务器没有在调试模式下运行,您已经收到了 500 错误页面。
-
我不想更正这个错误需要在这个错误发生时显示一个错误模板..