Django:NoReverseMatch

时间:2015-06-11 14:01:37

标签: django

在我的html模板中添加一行时,我得到一个error

<a href="{% url 'delete' posts.id %}" class="btn btn-primary btn-sm">Delete</a>

我的网址:

url(r'^delete/(?P<pk>[A-Za-z0-9\w|\W]+)/$', views.DeleteView.as_view(), name='delete'),

我的观点:

class DeleteView(deletePostForm, DeleteView):
    template_name = 'delete_confirm.html'
    success_url = reverse_lazy('home')

我该如何解决?

1 个答案:

答案 0 :(得分:0)

尝试使用:

<a href="{% url 'delete' %}{{posts.id}}/" class="btn btn-primary btn-sm">Delete</a>

由于posts在模板上下文中可用,因此请访问其ID。这将生成正确的链接,您将收到delete请求。