-1

在我的 html 中:

 <form action="/smartlogis/result_material/{{form.DBR_No.value}}/" method="POST">
    {{form.as_ul}}
    <input type="submit" value="Submit" /></form>
 <form action="/smartlogis/result_material/{{form.DBR_No.value}}/" method="GET">   

  <input type="submit" value="Delete" />
</form>

视图.py:

def Matedit1(请求,DBR_No):

f = Movement_In.objects.get(DBR_No=DBR_No)
if request.method == 'POST':

    form = Movement_ReceiptForm(request.POST, request.FILES, instance=f) 
    if form.is_valid():

        form.save()
        return HttpResponseRedirect('/thanks/')
else:
    print "ahj"
    if request.method == 'GET':
        print "dsfsf"
        form = Movement_ReceiptForm(request.POST, request.FILES, instance=f)
        if request.POST.get('delete'):
            form.delete()
            return HttpResponseRedirect('/smartlogis/matdelete.html/')

现在,当我单击删除按钮时,它会进入 else 循环,但不会删除表单。它直接去HttpResponseRedirect

4

1 回答 1

0

您的请求不能同时是 GET 和 POST 请求,因此无法调用 delete 语句。此外,如果您想删除“f”,您会想要

f.delete()

但再次重申,这甚至不会被调用。没有在表单或模型表单上定义 delete() 并没有引发错误的事实是由于在任何情况下都无法调用此代码。

于 2013-02-07T08:55:07.970 回答