-1
嘗試刪除Django中的對象時,收到此錯誤「TemplateDoesNotExist at/bookmarks/list/1/delete_link /」。Django刪除對象
在forms.py我:
class DeleteForm(forms.ModelForm):
class Meta:
model = Link
fields = []
在views.py:
def delete_link(request, link_id):
link_to_delete = get_object_or_404(Link, id=link_id)
context_dict = {'link_id': link_id}
if request.method == 'POST':
form = DeleteForm(request.POST, instance=link_to_delete)
if form.is_valid():
link_to_delete.delete()
return HttpResponseRedirect('bookmarks/list')
else:
form = DeleteForm(instance = link_to_delete)
template_vars = {'form': form}
return render_to_response(request, 'bookmarks/delete_link.html', template_vars)
urls.py:
url(r'^list/(?P<link_id>\w+)/delete_link/$', views.delete_link, name='delete_link'),
嵌入list.html(模板顯示鏈接列表,我希望每個旁邊都有刪除選項):
<a href='/bookmarks/list/{{ link.pk }}/delete_link/'> Delete</a>
你使用的是什麼版本的Django? – teewuane
錯誤消息似乎很清楚。你真的有這個模板嗎? –