模板.html
<tr id="head-{{ report_person.report_person.id}}">
<td style="width:150px;"><input type="button" name="delete" class="delete_icon" value="{{ report_person.report_person.id}}"/>
{{report_person.report_person.name }}</td>
<td> {{report_person.info.first_aid}}{{report_person.info.first_aid.label}}</td>
<td>{{report_person.info.sick_bay}}{{report_person.info.sick_bay.label}}</td></tr>
网址.py
(r'^who/$', 'new_report'),
视图.py
def method(request):
if request.method == 'POST':
form = ReportPersonForm(request.POST)
if 'delete_id' in request.POST: #To delete added names
ReportPerson.objects.filter(id=request.POST['delete_id']).delete()
Actions.objects.filter(id=request.POST['delete_id']).delete()
InjuredLocation.objects.filter(id=request.POST['delete_id']).delete()
return render
自定义确认弹出窗口以删除添加的数据。
<div class="delete_confirm" style="display:none">
<form method="post" action="." id="{{ report_person.report_person.id}}">
{% csrf_token %}
<h2> Are you sure</h2>
<br />
<div style="width:180px;float:right;margin:20px 5px 0 10px">
<button type="button" name="delete" class="delete_icon1" value="{{ report_person.report_person.id}}" />Delete</button>
<button style="margin-right:10px;" type="button" class="close" name="cancel" class="forward backicon">
<img src="{{ STATIC_URL }}images/button-icon-ir-back.png" width="12" height="17" alt="" />
Cancel</button>
</div>
</form>
</div>
javascript:
$('.delete_icon1').click(function() {
var csrf_token = $("#csrf_token").val();
var id = $(this).attr('value');
$.ajax({ // create an AJAX call...
data:{
csrfmiddlewaretoken: csrf_token,
delete_id:id
},
type:'POST',
url: '/report/who/', // the file to call
cache:false,
success: function() { // on success..
window.location.href = window.location;
}
});
return false;
});
以前我通过单击delete_icon
它工作正常的类来实现删除功能。现在我在删除之前添加了一个删除确认弹出框。弹出窗口正在显示,但是在单击删除按钮时我无法删除。value="{{ report_person.report_person.id}}"
没有传入弹出框是要删除的 ID。如果我单击删除,我会收到此错误
"ValueError at /report/who/
invalid literal for int() with base 10: ''"
在 FF 控制台中。我想知道如何将 id ( value="{{ report_person.report_person.id}}"
) 从 html 传递到模板。