所有网址中有一个不匹配

时间:2015-07-25 04:50:55

标签: django url-routing

我正在使用Django 1.8,我无法弄清楚为什么一个特定的网址没有匹配。

网址为/weapons。 Django正在添加一个尾随斜杠,我认为这是因为默认情况下APPEND_SLASH选项为true。即使我试图在没有斜线的情况下到达网址,它也会失败然后尝试斜线。

这是我得到的错误:

enter image description here

顶级urls.py

urlpatterns = [
    url (r'^admin/', include (admin.site.urls)),
    url (r'^', include ('core.urls', namespace = 'core')),
    url (r'^', include ('equipment.urls', namespace = 'equipment')),
]

core urls.py

urlpatterns = patterns [
    url (r'^$', views.index, name = 'index'),
]

设备urls.py

urlpatterns = [
    url (r'^equipment$', views.index, {'type':'index'}, name = 'index'),
    url (r'^weapons$', views.index, {'type':'weapons'}, name = 'weapons'),
    url (r'^armor$', views.index, {'type':'armor'}, name = 'armor'),
    url (r'^accessories$', views.index, {'type':'accessories'}, name = 'accessories'),
]

3 个答案:

答案 0 :(得分:0)

我愿意:

urlpatterns = [
   url (r'^admin/', include (admin.site.urls)),
   url (r'^home/', include ('core.urls', namespace = 'core')),
   url (r'^equipment/', include ('equipment.urls', namespace = 'equipment')),
]

urlpatterns = [
    url (r'^weapons/$', views.index, {'type':'weapons'}, name = 'weapons'), 
]

请注意django 1.8中的[]而不是patterns

你的网址看起来像是:

http://localhost:1000/equipment/weapons/ 

哪个有道理?

答案 1 :(得分:0)

尝试从^core/urls.py中的网址中删除前导equipment/urls.py

答案 2 :(得分:0)

原来这是一个缓存问题。我尝试使用Ctrl + F5,但它没有用,所以我尝试了隐身模式下的页面。所以我使用开发者工具重新加载页面,现在它可以工作。