NoReverseMatch,为什么django找不到网址?

时间:2016-07-12 19:13:48

标签: python django

我的网址有点问题,我搜索了几次,但没找到正确的答案。

我收到以下错误:

NoReverseMatch at /base/teams/
Reverse for 'base-home' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []

这是我的网址:

    来自项目的
  • from django.conf.urls import url, patterns, include
    from django.contrib import admin
    
    urlpatterns = patterns('',
    # Examples:
    
    url(r'^base/$', include('django.contrib.flatpages.urls'), name='base-home'),
    url(r'^base/contact/$', include('django.contrib.flatpages.urls'), name='base-contact'),
    url(r'^base/teams/', include('app.urls'), name='base-teams'),
    
    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
    
    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
    )
    
  • 来自应用程序的
  • from django.conf.urls import *
    urlpatterns = patterns('',
      url(r'^$', 'app.views.teams_list', name='teams'),
      url(r'^(?P<slug>[-\w\d]+)/$', 'app.views.teams_list', name='teams_slug'),
      url(r'^show/(?P<id>\d+)/$', 'app.views.show_personne', name='show_personne'),
    )
    

以下是模板中的调用:

<a class="navbar-brand" href="{% url 'base-home' %}">Website</a>

尝试加载页面“base / teams /”时会引发此错误。我不明白他为什么不匹配基本住宅视图名称......

感谢您的帮助, 分克

1 个答案:

答案 0 :(得分:1)

那是因为这一行

url(r'^base/$', include('django.contrib.flatpages.urls'), name='base-home'),

实际上并未解析为视图。相反,它是include声明。

请参阅How can I get the reverse url for a Django Flatpages template