我突然得到了以下无法解释的错误:
Django Version: 1.4.5
Python Version: 2.7.3
Traceback:
File "/home/webapp/.local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
101. request.path_info)
File "/home/webapp/.local/lib/python2.7/site-packages/newrelic-2.18.1.15/newrelic/hooks/framework_django.py" in wrapper
518. return wrapped(*args, **kwargs)
File "/home/webapp/.local/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
298. for pattern in self.url_patterns:
File "/home/webapp/.local/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
328. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/home/webapp/.local/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
323. self._urlconf_module = import_module(self.urlconf_name)
File "/home/webapp/.local/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
File "/home/webapp/myApp/cmap/urls.py" in <module>
8. from django.contrib import admin
File "/home/webapp/.local/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in <module>
4. from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
File "/home/webapp/.local/lib/python2.7/site-packages/django/contrib/admin/options.py" in <module>
8. from django.contrib.admin import widgets, helpers
Exception Type: ImportError at /
Exception Value: cannot import name widgets
我可以使用Django shell和python shell成功导入小部件(from django.contrib.admin import widgets
),但是当我运行我的网络应用程序时它不起作用。
我用来启动应用的命令是:
newrelic-admin run-program python manage.py run_gunicorn ...
我已经回顾了我最近的提交,并且没有看到任何可能与此错误相关的内容。
答案 0 :(得分:1)
如果不知道应用中的实际内容,很难确定发生了什么。但是,在过去,当我遇到类似的ImportError
时,最常见的原因是:
PYTHONPATH
)pip install ...
)答案 1 :(得分:0)
我在追溯中看到以下一行 -
File "/home/webapp/myApp/cmap/urls.py" in <module>
8. from django.contrib import admin
File "/home/webapp/.local/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in <module>
看起来像循环导入问题,你真的需要在该文件中导入吗?
答案 2 :(得分:0)
我最终将此跟踪到导致问题的提交。我已将此添加到settings.py中的日志记录配置:
function isElementInViewport (el) {
var rect = el[0].getBoundingClientRect();
return (rect.top>-1 && rect.bottom <= $(window).height());
}
...以为我在添加默认记录器。这导致了一系列无法解释的错误,包括我在这里发布的错误。删除它修复了一切。
请注意,Ming的答案是解决此错误的最佳通用答案。