django urlresolver投掷错误

时间:2014-12-06 12:32:43

标签: python django django-views django-testing django-tests

我创建了一个Django项目foo

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

views.py中,我创建了两个基于类的视图HomePageListPageurls.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'}

这里出了什么问题?默认根网址&#39; /&#39;正在解决,但列出了&#39;没有解决

1 个答案:

答案 0 :(得分:2)

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

>>resolve('/list')