在我的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>
views.py:
def Matedit1(request,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
答案 0 :(得分:0)
您的请求不能同时是GET和POST请求,因此无法调用delete语句。此外,如果你想删除“f”,你会想要
f.delete()
但再次重申,甚至不会这样说。它没有引发delete()未在表单或模型表单上定义的错误这一事实是由于在任何条件下都无法调用此代码。