Django:更改为相对URL时的NoReverseMatch

时间:2016-10-04 18:36:07

标签: django

当我更改行

<a href="/rango/category/{{category.slug}}">

<a href="{% url 'show_category' category.slug %}">

我得到NoReverseMatch。出了什么问题?

网址:

app_name="rango"
urlpatterns = [
    url(r'^$', views.index, name='index'),
    url(r'^about/', views.about, name='about'),
    url(r'^category/(?P<category_name_slug>[\w\-]+)/',
        views.show_category, name='show_category'),
    url(r'^add_category/$', views.add_category, name='add_category'),
    url(r'^category/(?P<category_name_slug>[\w\-]+)/add_page/$', views.add_page, name='add_page'),
]

enter image description here

1 个答案:

答案 0 :(得分:0)

您已将应用名称定义为rango。您需要在撤消网址时使用此功能:

<a href="{% url 'rango:show_category' category.slug %}">