在我的html模板中添加一行时,我得到一个
<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')
我该如何解决?
答案 0 :(得分:0)
尝试使用:
<a href="{% url 'delete' %}{{posts.id}}/" class="btn btn-primary btn-sm">Delete</a>
由于posts
在模板上下文中可用,因此请访问其ID。这将生成正确的链接,您将收到delete
请求。