我创建了一个 Django 项目foo
。
├── manage.py
└── foo
├── __init__.py
├── settings.py
├── templates
│ ├── xyz.html
│ └── abc.html
├── tests.py
├── urls.py
├── views.py
└── wsgi.py
在views.py
中,我创建了两个基于类的视图HomePage
和ListPage
路由配置,如下所示urls.py
:
urlpatterns = patterns('',
url(r'^$', HomePage.as_view() , name='home'),
url(r'^list$', ListPage.as_view(), name='list'),
# url(r'^admin/', include(admin.site.urls)),
)
引发错误:
(InteractiveConsole)
>>> import django
>>> django.setup()
>>> from django.core.urlresolvers import resolve
>>> resolve('/')
ResolverMatch(func=<function HomePage at 0x7f77769bb9d8>, args=(), kwargs={}, url_name='home', app_name='None', namespace='')
>>> resolve('list')
Traceback (most recent call last):
File "<console>", line 1, in <module>
...
raise Resolver404({'path': path})
django.core.urlresolvers.Resolver404: {'path': 'list'}
这里出了什么问题?默认根 url '/' 正在解析,但 'list' 没有解析