Django删除对象

时间:2014-02-20 03:31:25

标签: python django

我在尝试删除Django中的对象时收到此错误“TemplateDoesNotExist at / bookmarks / list / 1 / delete_link /”。

在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>

1 个答案:

答案 0 :(得分:0)

下面:

return render_to_response(request, 'bookmarks/delete_link.html', template_vars)

Django无法找到您的模板。你在TEMPLATES_DIRS中有吗?