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