带有
的Django barfsImportError at /store/
No module named store
但是有调试信息就是设置
INSTALLED_APPS =
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'store')
Environment:
Request Method: GET
Request URL: http://localhost:8000/
Django Version: 1.4.5
Python Version: 2.7.3
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'store')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware')
Traceback:
File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/home/paul/cs462/store/store/views.py" in main
37. return redirect(reverse('django.contrib.auth.views.login'))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse
476. return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _reverse_with_prefix
363. possibilities = self.reverse_dict.getlist(lookup_view)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse_dict
276. self._populate()
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
253. for name in pattern.reverse_dict:
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in reverse_dict
276. self._populate()
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in _populate
265. lookups.appendlist(pattern.callback, (bits, p_pattern, pattern.default_args))
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in callback
216. self._callback = get_callable(self._callback_str)
File "/usr/lib/python2.7/site-packages/django/utils/functional.py" in wrapper
27. result = func(*args)
File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py" in get_callable
105. not module_has_submodule(import_module(parentmod), submod)):
File "/usr/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
35. __import__(name)
Exception Type: ImportError at /
Exception Value: No module named store
shell工作得很好(我尝试的),但是我的每个页面都会显示此错误。在应用程序中没有“存储”意味着导入模块???
编辑:我多次使用Django进行项目。这是几个小时前的工作。商店/中有一个空白__init__.py
文件。而且,通过使用print语句,我能够确定它被执行(两次)。 urls.py
和models.py
也已执行(但不是views.py
)。我不知道我能做些什么才能得到这个错误。
答案 0 :(得分:13)
如果不是版本控制,我将永远不会发现这一点。事实上,我花了将近一个小时来追踪它。
错误在store / urls.py中:
urlpatterns = patterns('store.views',
url(r'^$', 'main'),
url(r'^new_delivery_user/$', 'new_delivery_user'),
...
url(r'^event_signal/$', 'store.views.event_signal'), # problem
)
我已将项目url.py中的最后一个网址移动到此特定于应用的网址,该网址使用简写的“store.views”来预先添加每个视图。
应该出现了:
url(r'^event_signal/$', 'event_signal'),
答案 1 :(得分:0)
感谢Paul Draper,我更改了
re_path('api/(?P<version>(v1|v2))/', include('music.urls'))
进入:
re_path('api/(?P<version>(v1|v2))/', include('musicservices.music.urls'))
问题解决了。