2

我创建了一个 Django 项目foo

├── manage.py
└── foo
    ├── __init__.py
    ├── settings.py
    ├── templates
    │   ├── xyz.html
    │   └── abc.html
    ├── tests.py
    ├── urls.py
    ├── views.py
    └── wsgi.py

views.py中,我创建了两个基于类的视图HomePageListPage 路由配置,如下所示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' 没有解析

4

1 回答 1

3

这是我的一个愚蠢的错误:)。虽然它可能对某人有帮助。

尝试

>>resolve('/list')
于 2014-12-06T13:10:56.400 回答