0

为什么会返回NoReverseMatch

html:

{% url vote thing.id thing.slug %}

网址.py:

url(r'^vote/(?P<object_id>\d+)/(?P<slug>[w\-]+)/$', 'app.views.the_view', name='vote'),

视图.py:

def the_view(request, object_id, slug):
    thing_list = Thing.objects.all()
    return render(request, 'vote.html', {'thing_list':thing_list})
4

1 回答 1

3

您必须使用以下内容:

{% url vote object_id=thing.id slug=thing.slug %}

因为您已经在模式中明确命名了匹配的组。

请注意,从 Django 1.5 开始,您必须执行以下操作:

{% url 'vote' .. %}

代替:

{% url vote ..%}

在此处的 django 文档中查看它https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#url

于 2012-12-26T03:20:22.943 回答