2014-12-06 124 views
1

我創建了一個Django項目foodjango urlresolver投擲錯誤

├── 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'} 

什麼錯這裏?默認的根網址'/'正在解析,但'列表'不解決

+2

您是否嘗試過解決( 「/列表」) – biobirdman 2014-12-06 13:05:26

+0

這是一個小白錯誤。謝謝 – surenyonjan 2014-12-06 13:11:56

回答

1

這是我的一個愚蠢的錯誤:)。雖然這可能對某人有所幫助。

嘗試

>>resolve('/list')