从第三方应用程序导入视图时,Django应用程序抛出虚假异常

时间:2010-12-21 16:50:21

标签: django django-apps

我正在研究一个Django应用程序,当尝试从第三方应用程序(Solango,具体)导入模块时偶尔会抛出ViewDoesNotExist异常。通过“偶尔”,我的意思往往是令人讨厌,但绝对是少数请求。 Solango位于应用程序的PYTHONPATH上,可以通过控制台可靠地导入。在本地开发期间也不会发生错误,因此可能与服务器设置有关(应用程序在守护进程模式下使用Apache + mod_wsgi)。

这是一个堆栈跟踪,显示管理员中发生的错误(虽然它几乎发生在网站的每个页面上):

Traceback:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/handlers/base.py" in get_response
  92.                 response = callback(request, *callback_args, **callback_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in root
  445.             return self.index(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/views/decorators/cache.py" in _wrapped_view_func
  44.         response = view_func(request, *args, **kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/contrib/admin/sites.py" in index
  342.             context_instance=template.RequestContext(request)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/shortcuts/__init__.py" in render_to_response
  20.     return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader.py" in render_to_string
  108.     return t.render(context_instance)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  97.         return compiled_parent.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  178.         return self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  245.                     return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  255.             return self.nodelist_true.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/loader_tags.py" in render
  24.         result = self.nodelist.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render
  778.                 bits.append(self.render_node(node, context))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/__init__.py" in render_node
  791.         return node.render(context)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/template/defaulttags.py" in render
  372.             url = reverse(self.view_name, args=args, kwargs=kwargs)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  265.             *args, **kwargs)))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in reverse
  238.         possibilities = self.reverse_dict.getlist(lookup_view)
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  165.                     for name in pattern.reverse_dict:
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_reverse_dict
  173.                     lookups.appendlist(pattern.callback, (bits, p_pattern))
File "/home/nybooks/ve/lib/python2.5/site-packages/django/core/urlresolvers.py" in _get_callback
  134.             raise ViewDoesNotExist, "Could not import %s. Error was: %s" % (mod_name, str(e))

Exception Type: ViewDoesNotExist at /admin/
Exception Value: Could not import solango.views. Error was: cannot import name settings

关于导致问题的原因,或者至少我可以如何调试它的任何想法?

2 个答案:

答案 0 :(得分:1)

您的网络服务器没有文件描述符。为守护进程模式重新配置mod_wsgi。

答案 1 :(得分:0)

您可以在导入的代码中具有顺序依赖性。这不会出现在开发服务器中,因为很多东西都是预加载的,而不是生产WSGI服务器。

所以最终它就像你使用Django一样。在此期间,您可以尝试以下建议:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

获取WSGI脚本文件的备用内容,并查看问题是否消失。