Python Django:没有名为“app”的模块
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15404580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Django: No module named 'app'
提问by Paul Draper
Django barfs with
Django 与
ImportError at /store/
No module named store
But right there is the debug message there is the setting
但是就在调试消息那里是设置
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
The shell works just fine (for what I try), but this error is displayed at every page I have. Doesn't having 'store' in the apps means that the module is imported???
shell 工作得很好(对于我的尝试),但是这个错误显示在我拥有的每个页面上。应用程序中没有“商店”意味着模块已导入???
EDIT: I've used Django for project many times. This was working a few hours ago. There is a blank __init__.pyfile in store/. Moreover, by using a print statement, I was able to determine that this gets executed (twice). urls.pyand models.pyalso are executed (but not views.py). I have no idea what I could do to get this error.
编辑:我已经多次将 Django 用于项目。这是几个小时前的工作。__init__.pystore/ 中有一个空白文件。此外,通过使用打印语句,我能够确定它被执行(两次)。urls.py并且models.py也被执行(但不是views.py)。我不知道我能做些什么来得到这个错误。
采纳答案by Paul Draper
If it were not for version control, I would have never found this. As it was, it took me almost an hour to track it down.
如果不是为了版本控制,我永远不会发现这个。事实上,我花了将近一个小时才找到它。
The mistake was in store/urls.py:
错误在 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
)
I had moved the last URL from the project url.py to this app-specific one, which used the shorthand 'store.views' for prepending each of the views.
我已将项目 url.py 中的最后一个 URL 移动到这个特定于应用程序的 URL,它使用速记“store.views”来预先添加每个视图。
It should have appeared:
它应该出现:
url(r'^event_signal/$', 'event_signal'),
回答by user1743724
thanks to Paul Draper, after I changed the
感谢 Paul Draper,在我改变了
re_path('api/(?P<version>(v1|v2))/', include('music.urls'))
into :
进入 :
re_path('api/(?P<version>(v1|v2))/', include('musicservices.music.urls'))
the problem resolved.
问题解决了。

