template.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>
urls.py
(r'^who/$', 'new_report'),
views.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
类来实现删除功能。现在我在删除之前添加了删除确认弹出框.Popup正在显示,但是点击删除按钮后我无法删除。 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传递给模板。