我开始使用django-nose因为我想通过python manage.py测试只运行我的应用程序测试,但我遇到了这个ImportError:没有名为urls的模块。
这个项目正在使用Django 1.4。
文件夹结构如下:
project
├── manage.py
├── project
├── apps
│ ├── app1
| ├── __init__.py
│ ├── tests.py
│ └── app2
│ └── app3
├── settings.py
├── urls.py
└── views.py
但是,当我运行python manage.py测试时,我得到一个ImportError:没有名为urls的模块:
Traceback (most recent call last):
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/middleware/locale.py", line 21, in process_request
check_path = self.is_language_prefix_patterns_used()
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/middleware/locale.py", line 54, in is_language_prefix_patterns_used
for url_pattern in get_resolver(None).url_patterns:
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 328, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
File "/Users/huey/.virtualenvs/myvirtualenv/lib/python2.7/site-packages/django/utils/importlib.py", line 38, in import_module
__import__(name)
ImportError: No module named urls
我尝试过的东西不起作用:
name: project.urls package: None sys.path: ‘/Users/huey/code’ ‘/Users/huey/code/project’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python27.zip’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-darwin’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-mac’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/plat-mac/lib-scriptpackages’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-tk’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-old’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/lib-dynload’ ‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7’ ‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin’ ‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk' ‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac’ ‘/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages’ ‘/Users/huey/.virtualenvs/projectfresh/lib/python2.7/site-packages’ ‘/Users/huey/code/project/project/apps’ ‘/Users/huey/code/project/project/common’ ‘/Users/huey/code/project/project/lib’
ROOT_URLCONF是'project.urls'
我不知道从哪里开始。有什么想法吗?
答案 0 :(得分:1)
我明白了。即使我删除了 init .py,我也忘了删除相应的.pyc文件。