我有一个非常简单的Django应用程序我开始。我已经浏览了djangoproject.com上的教程并开始工作,现在我正在构建我的网站。但是,我无法让我的网址路由工作。我的目录结构是
/dartagnan
--/menu
__init__.py
admin.py
models.py
urls.py
views.py
__init__.py
settings.py
urls.py
我的模型正在运行,我已经(有)管理员正在运行。我添加了菜单/网址
from django.conf.urls import patterns, url
from dartagnan.menu import views
urlpatterns = patterns('',
url(r'^$', views.index, name='index')
)
我安装的应用包括bot&#d; dartagnan'和' dartagnan.menu'
我将顶级urls.py更新为
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^menu/', include('menu.urls')),
)
现在当我尝试访问时,说localhost / menu我得到错误:
ImportError at /menu
No module named menu.urls
我已尝试过dartagnan.menu.urls'以及其他一些变体。我试图找到一个类似的问题来学习,但是如果有人遇到同样的问题,我在python和django上太新了,意识到它们是相同的。
编辑:每个请求,错误跟踪
环境:
Request Method: GET
Request URL: http://127.0.0.1:8000/menu
Django Version: 1.6.5
Python Version: 2.7.5
Installed Applications:
('django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'dartagnan',
'dartagnan.menu')
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 "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
88. response = middleware_method(request)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/middleware/common.py" in process_request
71. if (not urlresolvers.is_valid_path(request.path_info, urlconf) and
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/urlresolvers.py" in is_valid_path
596. resolve(path, urlconf)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
476. return get_resolver(urlconf).resolve(path)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
337. for pattern in self.url_patterns:
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
365. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
360. self._urlconf_module = import_module(self.urlconf_name)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
40. __import__(name)
File "/Users/Christopher/Sourcecode/dartagnan/dartagnan/urls.py" in <module>
19. url(r'^menu/', include('menu.urls')),
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/conf/urls/__init__.py" in include
26. urlconf_module = import_module(urlconf_module)
File "/Users/Christopher/dartagnan-base-env/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
40. __import__(name)
Exception Type: ImportError at /menu
Exception Value: No module named menu.urls